码迷,mamicode.com
首页 > Windows程序 > 详细

C#桌面程序设计复习

时间:2018-12-06 21:23:20      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:ati   iap   i++   quic   enter   lips   微软   dir   except   

GGG
//屏幕高度
int ScreenH = 1080;
this.Location = new Point(this.Location.X, ScreenH - this.Height - 20);
//关闭本窗体,打开主窗体
this.Hide();
FrmQQMain frmQQMain = new FrmQQMain();
frmQQMain.ShowDialog();
//鼠标进入时,变成红色
label1.ForeColor = Color.Red;
//鼠标离开时,背景变透明
pictureBox1.BackColor = Color.Transparent;
//颜色浅灰半透明
picShrink.BackColor = Color.FromArgb(50,200,200,200);
//鼠标进入时,切换另一张图片
picLogin.BackgroundImage = Properties.Resources.iconqq;
//鼠标拖动窗体方法
bool isDrag;
Point ClickPoint;
private void Frm1_MouseDown(object sender, MouseEventArgs e)
{
isDrag = true;
ClickPoint = new Point(e.X ,e.Y );
}

    private void Frm1_MouseMove(object sender, MouseEventArgs e)
    {
        if (isDrag == true)
            this.Location = new Point(this .Location .X +e.X -ClickPoint .X 
                ,this .Location .Y +e.Y -ClickPoint .Y );
        ClickPoint.X = e.X;
        ClickPoint.Y = e.Y;
    }

    private void Frm1_MouseUp(object sender, MouseEventArgs e)
    {
        isDrag = false;
    }

//随机出现按钮方法
Random r = new Random();
button2.Location = new Point(r.Next ()%(this .Width -button2 .Width )
,r .Next ()%(this.ClientSize .Height -button2 .Height ));

//打开资源管理器(click事件中)
OpenFileDialog ofd=new openfiledialog();//初始化打开文件夹类
ofd.ShowDialog();//显示资源管理器
//显示图片
(click事件外)image imgOriginal;//定义一张图片
(click事件里) string strFileName = ofd.FileName;//获取该位置的文件名
imgOriginal = Image.FromFile(strFileName);//获取选取的图片
pictureBox1.BackgroundImage = imgOriginal;//显示图片

//图片底片化(click事件里)
bitmap bmp=new bitmap(imgoriginal);//从现有的图像初始化位图类
for(int i=0;i<bmp.width;i++)
{
for(int j=0;j<bmp.height;j++)
{
color c=bmp.getpixel(i,j);//获得原来像素点颜色
color cafter=color.fromargb(255-c.r,255-c.g,255-c.b);//改变
bmp.setpixel(i,j,cafter); //设置回去
}
}
picturebox2.backgroundimage=bmp;

//保存修改后的图片(click事件中)
savefiledialog sfd=new savefiledialog();//初始化保存类
sfd.showdialog();//重载显示资源管理器界面
picturebox2.backgroundimage.save(sfd.filename+".jpg");//获取控件中的背景图片AAA
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DamonQQ
{
public partial class FrmLogin : Form
{
public FrmLogin()
{
InitializeComponent();
}

    private void pictureBox6_Click(object sender, EventArgs e)
    {

    }

    private void textBox3_TextChanged(object sender, EventArgs e)
    {

    }

    private void checkBox2_CheckedChanged(object sender, EventArgs e)
    {

    }

    private void Form1_Load(object sender, EventArgs e)
    {
        //屏幕的高度
        int ScreenH=1080;
        this.Location = new Point(this.Location.X, ScreenH - this.Height - 20);
    }

    private void label1_Click(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        //关闭本窗体,打开qq好友窗体
        this.Hide();
        FrmQQMain frmQQMain = new FrmQQMain();
        frmQQMain.ShowDialog();
    }

    private void pictureBox8_Click(object sender, EventArgs e)
    {
        //关闭本窗体,打开QQ设置窗体
        this.Hide();
        QQsetup QQsetup = new QQsetup();
        QQsetup.ShowDialog();
       
    }

    private void pictureBox9_Click(object sender, EventArgs e)
    {
        
    }

    private void pictureBox10_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void label1_MouseEnter(object sender, EventArgs e)
    {
        //鼠标进入时,标签变成黑色
        lblFoundCode.ForeColor = Color.Black;
       

    }

    private void label1_MouseLeave(object sender, EventArgs e)
    {
        //鼠标离开时,标签变成灰色
        lblFoundCode.ForeColor = Color.Gray;
    }

    private void checkBox2_MouseEnter(object sender, EventArgs e)
    {
        //鼠标进入时,标签变成黑色
        chkRemember.ForeColor = Color.Black;
    }

    private void checkBox2_MouseLeave(object sender, EventArgs e)
    {
        //鼠标离开时,标签变成灰色
        chkRemember.ForeColor = Color.Gray;
    }

    private void checkBox1_MouseEnter(object sender, EventArgs e)
    {
        //鼠标进入时,标签变成黑色
        chkAutoLogin.ForeColor = Color.Black;
    }

    private void checkBox1_MouseLeave(object sender, EventArgs e)
    {
        //鼠标离开时,标签变成灰色
        chkAutoLogin.ForeColor = Color.Gray;
    }

    private void label2_MouseEnter(object sender, EventArgs e)
    {
        //鼠标进入时,标签变成黑色
        lblRegister.ForeColor = Color.Black;
    }

    private void label2_MouseLeave(object sender, EventArgs e)
    {

        //鼠标离开时,标签变成灰色
        lblRegister.ForeColor = Color.Gray;
    }

    private void pictureBox10_MouseEnter(object sender, EventArgs e)
    {
        //鼠标进入时 图片背景变红
        picClose.BackColor = Color.Red;
    }

    private void pictureBox10_MouseLeave(object sender, EventArgs e)
    {
        picClose.BackColor = Color.Transparent;
    }

    private void pictureBox9_MouseEnter(object sender, EventArgs e)
    {
        //颜色浅灰色半透明
        picShrink.BackColor = Color.FromArgb(50, 200, 200, 200);
       
    }

    private void pictureBox9_MouseLeave(object sender, EventArgs e)
    {
        picShrink.BackColor = Color.Transparent;
    }

    private void pictureBox2_MouseEnter(object sender, EventArgs e)
    {
        //变成蓝色小企鹅
        picLogin.BackgroundImage = Properties.Resources.iconqq;//此处应为蓝色
        
    }

    private void pictureBox5_MouseEnter(object sender, EventArgs e)
    {
         picLoginTail.BackgroundImage = Properties.Resources.down_en;
    }

    private void pictureBox5_MouseLeave(object sender, EventArgs e)
    {
        picLoginTail.BackgroundImage = Properties.Resources.down_dis;
    }



    bool isDrag;//是否拖动窗体
    Point clickPoint;
    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
        isDrag = true;
        clickPoint = new Point(e.X, e.Y);
    }
   // Point movePoint;
    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {
        if (isDrag ==true )
            this.Location = new Point(this.Location.X + e.X - clickPoint.X,
        this.Location .Y +e.Y -clickPoint .Y );
        clickPoint .X =e.X ;
        clickPoint .Y =e.Y ;
    }

    private void Form1_MouseUp(object sender, MouseEventArgs e)
    {
        isDrag = false;
    }










    bool isMoveout;
    bool isMoveback;
    private void pictureBox1_MouseEnter(object sender, EventArgs e)
    {
        //加号弹出
        timer1.Enabled = true;
        isMoveout = true;
    }

    private void pictureBox1_MouseLeave(object sender, EventArgs e)
    {
        //加号弹回

        isMoveout = false ;
        isMoveback = true;
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        if (isMoveout)
        {
            picMultiUser.Location = new Point(picMultiUser.Location.X + 10, picMultiUser.Location.Y);
            if (picMultiUser.Location.X >= 277)
            {
                timer1.Enabled = false;
                return;
            }
        }
        else 
        {
            picMultiUser.Location = new Point(picMultiUser.Location.X - 10, picMultiUser.Location.Y);

            if (picMultiUser.Location.X <= 178)
            {
                timer1.Enabled = false;
                return;
            }
        }
    }

    private void picSet_MouseEnter(object sender, EventArgs e)
    {
        picSet.BackColor = Color.FromArgb(50, 200, 200, 200);
    }

    private void picSet_MouseLeave(object sender, EventArgs e)
    {
        picSet.BackColor = Color.Transparent;
    }

    private void picQuickMark_MouseEnter(object sender, EventArgs e)
    {
        picQuickMark.BackgroundImage = Properties.Resources.tdcode1;
    }

    private void picLoginTail_Click(object sender, EventArgs e)
    {

    }

    private void picQuickMark_Click(object sender, EventArgs e)
    {
        //关闭本窗体,打开二维码窗体
        this.Hide();
        QuickMark QuickMark = new QuickMark();
        QuickMark.ShowDialog();
    }

    private void picQuickMark_MouseLeave(object sender, EventArgs e)
    {
        picQuickMark.BackgroundImage = Properties.Resources.tdcode;
    }

    private void picKeyboard_MouseEnter(object sender, EventArgs e)
    {
        picKeyboard.BackgroundImage = Properties.Resources.keyboard1;
    }

    private void picKeyboard_MouseLeave(object sender, EventArgs e)
    {
        picKeyboard.BackgroundImage = Properties.Resources.keyboard;
    }

    private void picMultiUser_Click(object sender, EventArgs e)
    {

    }

    private void lblRegister_Click(object sender, EventArgs e)
    {

    }

    private void picKeyboard_Click(object sender, EventArgs e)
    {

    }

}

}

BBB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DamonResign
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void pictureBox1_Click(object sender, EventArgs e)
    {

    }

    private void pictureBox1_Click_1(object sender, EventArgs e)
    {
       

    }

    private void button2_MouseMove(object sender, MouseEventArgs e)
    {
      
    }

    private void label4_Click(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {

    }

    private void button2_MouseEnter(object sender, EventArgs e)
    {
        Random r = new Random();
        button2.Location = new Point(r.Next() % (this.Width - button2.Width),
            r.Next() % (this.ClientSize.Height - button2.Height));
    }

    private void button1_Click(object sender, EventArgs e)
    {
        this.Hide();
        Form2  form2 = new Form2 ();
        form2.ShowDialog();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }







                } 
    }
    

CCC
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace DamonMusic
{
public partial class Form1 : Form
{
private String[] songs;
private String[] lyrics;
private String[] pics;
private int songPointer = 0;

    private Label[] lyricLabels = new Label[100];

    public Form1()
    {
        InitializeComponent();
    }

    // type = 1 下一首 type = -1 上一首
    private int checkBound(int songPointer, int type){
        Boolean arrivedMaximum = false;
        Boolean arrivedMinimum = false;
        if(type == 1)
            songPointer += 1;
        else{
            songPointer -= 1;
        }
        if (songPointer == songs.Length) {
            arrivedMaximum = true;
        }
        if (songPointer == -1)
        {
            arrivedMinimum = true;
        }
        if (arrivedMaximum) {
            songPointer = 0;
        }
        if (arrivedMinimum) {
            songPointer = songs.Length - 1;
        }
        return songPointer;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        songs = Directory.GetFiles("song", "*.mp3");
        lyrics = Directory.GetFiles("lyric", "*.lrc");
        pics = Directory.GetFiles("image", "*.jpg");
        //相对路径
        if (songs.Length != 0){
            axWindowsMediaPlayer1.URL = songs[songPointer];
            LyricFiles lyricFiles = new LyricFiles();
            lyricFiles.LoadLyric(lyrics[songPointer]);
            int yStep = 0;
            for (int i = 0; i < lyricFiles.lstLyric.Count; i++)
            {
                Label lblLyric = new Label();
                lblLyric.Size = new System.Drawing.Size(500, 30);
                lblLyric.BackColor = Color.Transparent;
                lblLyric.ForeColor = Color.White;
                lblLyric.Font = new System.Drawing.Font("微软雅黑", 14);
                lblLyric.Text = lyricFiles.lstLyric[i].strLyric;
                lblLyric.Location = new Point(60, yStep);
                yStep += 40;
                lyricLabels[i] = lblLyric;
                this.Controls.Add(lblLyric);
            }
            this.BackgroundImage = Image.FromFile(pics[songPointer]);
            //songPointer = checkBound(songPointer,1);

         }
        else axWindowsMediaPlayer1.URL = null;

        axWindowsMediaPlayer1.Ctlcontrols.stop();
       
        //初始化 准备工作
        pnlControlBar.BackColor = Color.FromArgb(127, 200, 200, 200);
        
    }

    private void pictureBox1_Click(object sender, EventArgs e)
    {

    }

    private void pictureBox2_Click(object sender, EventArgs e)
    {

    }

    bool isplay = false;
    private void pictureBox9_Click(object sender, EventArgs e)
    {
        
        isplay = !isplay;
        //播放歌曲
        if (isplay)
        {
            lblShowDuration.Text = axWindowsMediaPlayer1.currentMedia.durationString;
            axWindowsMediaPlayer1.Ctlcontrols.play();
            picPlay.BackgroundImage = Properties.Resources.pause_circle_o;
        }
        else//暂停播放
        {
            axWindowsMediaPlayer1.Ctlcontrols.pause();
            picPlay.BackgroundImage=Properties.Resources.play_circle_o;
        }

        //LyricFiles lyricFiles = new LyricFiles();
        //lyricFiles.LoadLyric("lyric/音阙诗听-红昭愿.lrc");
        //int yStep = 0;
        //for (int i = 0; i < lyricFiles.lstLyric.Count; i++)
        //{
        //    Label lblLyric = new Label();
        //    lblLyric.Size = new System.Drawing.Size(500, 30);
        //    lblLyric.BackColor = Color.Transparent;
        //    lblLyric.ForeColor=Color .White ;
        //    lblLyric.Font=new System .Drawing .Font ("微软雅黑",14);
        //    lblLyric.Text = lyricFiles.lstLyric[i].strLyric;
        //    lblLyric.Location = new Point (60,yStep );
        //    yStep +=40;
        //    lyricLabels[labelPointer] = lblLyric;
        //    labelPointer += 1;
        //    this.Controls.Add(lblLyric);
        //}

        //int currentLyricLine;
        //for (int i = 0; i < lyricFiles.lstLyric.Count; i++)
        //{
          //  if (axWindowsMediaPlayer1.Ctlcontrols.currentPosition > lyricFiles.lstLyric[currentLyricLine].totSecond)
            //{
              //  for (int j = 0; j < lstLbl.Count; j++)
                //{
                  //  if (j == currentLyricLine)
                    //{
                     //   lstLbl[j].ForeColor = Color.Yellow;
                       // lstLbl[j ].Font=new Font ("微软雅黑",18);
                   // }
                    //else
                    //{
                      //  lstLbl[j].ForeColor = Color.White ;
                        //lstLbl[j ].Font=new Font ("微软雅黑",10);
                    //}
                //}
                //currentLyricLine ++;
            //}
         //}
        //lstLbl[j].Location=new Point(lstLbl[j].Location.X,LstLbl[j].Location.Y+20);


        //lyricFiles.lstLyric[1];
        
        //打开文件
     //  Encoding encode = Encoding.GetEncoding("GB2312");
     //  FileStream fs=new FileStream ("音阙诗听-红昭愿.lrc",FileMode .Open );
     //  StreamReader  sr=new StreamReader (fs,encode  );
     // 
     //  string line = sr.ReadLine();
     //  //操作文件
     //  //richTextBox1.Text = sr.ReadToEnd();
     //  //关闭文件
     //  sr.Close();
     //  fs.Close();
    }

    private void pictureBox10_Click(object sender, EventArgs e)
    {
            isplay = true;

            for (int i = 0; i < 100; i++)
            {
                if (lyricLabels[i] == null) {
                    continue;
                }
                this.Controls.Remove(lyricLabels[i]);
            }

            songPointer = checkBound(songPointer, 1);
            axWindowsMediaPlayer1.URL = songs[songPointer];
            axWindowsMediaPlayer1.Ctlcontrols.play();
            picPlay.BackgroundImage = Properties.Resources.pause_circle_o;

            LyricFiles lyricFiles = new LyricFiles();
            lyricFiles.LoadLyric(lyrics[songPointer]);
            int yStep = 0;
            for (int i = 0; i < lyricFiles.lstLyric.Count; i++)
            {
                Label lblLyric = new Label();
                lblLyric.Size = new System.Drawing.Size(500, 30);
                lblLyric.BackColor = Color.Transparent;
                lblLyric.ForeColor = Color.White;
                lblLyric.Font = new System.Drawing.Font("微软雅黑", 14);
                lblLyric.Text = lyricFiles.lstLyric[i].strLyric;
                lblLyric.Location = new Point(60, yStep);
                yStep += 40;
                lyricLabels[i] = lblLyric;
                this.Controls.Add(lblLyric);
            }

            this.BackgroundImage = Image.FromFile(pics[songPointer]);
    }

    private void pictureBox8_Click(object sender, EventArgs e)
    {
        isplay = true;

        for (int i = 0; i < 100; i++)
        {
            if (lyricLabels[i] == null)
            {
                continue;
            }
            this.Controls.Remove(lyricLabels[i]);
        }

        songPointer = checkBound(songPointer, -1);
        axWindowsMediaPlayer1.URL = songs[songPointer];
        axWindowsMediaPlayer1.Ctlcontrols.play();
        picPlay.BackgroundImage = Properties.Resources.pause_circle_o;

        LyricFiles lyricFiles = new LyricFiles();
        lyricFiles.LoadLyric(lyrics[songPointer]);
        int yStep = 0;
        for (int i = 0; i < lyricFiles.lstLyric.Count; i++)
        {
            Label lblLyric = new Label();
            lblLyric.Size = new System.Drawing.Size(500, 30);
            lblLyric.BackColor = Color.Transparent;
            lblLyric.ForeColor = Color.White;
            lblLyric.Font = new System.Drawing.Font("微软雅黑", 14);
            lblLyric.Text = lyricFiles.lstLyric[i].strLyric;
            lblLyric.Location = new Point(60, yStep);
            yStep += 40;
            lyricLabels[i] = lblLyric;
            this.Controls.Add(lblLyric);
        }
        this.BackgroundImage = Image.FromFile(pics[songPointer]);
    }
}

}

DDD
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ImageProcessDamon
{
public partial class Form1 : Form
{
//图像处理主界面
public Form1()
{
InitializeComponent();
}

    Image imgOriginal;
   
    //打开一张图片
    private void btnOpenimage_Click(object sender, EventArgs e)
    {
     
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.ShowDialog(); 


        string strFileName = ofd.FileName;

        imgOriginal = Image.FromFile(strFileName);
        pictureBox1 .BackgroundImage = imgOriginal;
    }
    //底片处理
    private void button2_Click(object sender, EventArgs e)
    {
        Bitmap bmp = new Bitmap( imgOriginal);
       
        for (int i = 0; i < bmp.Width ; i++) 
        {
            for (int j = 0; j < bmp.Height ; j ++)
            {
                //获得原来像素点颜色
                Color c = bmp.GetPixel(i , j);
                //改变
                Color cAfter = Color.FromArgb(255 - c.R, 255 - c.G, 255 - c.B);
                //设置回去
                bmp.SetPixel(i, j, cAfter);
            }
        }
        picAfter.BackgroundImage = bmp;
    }
    //灰度化
    private void button2_Click_1(object sender, EventArgs e)
    {
        Bitmap bmp = new Bitmap(imgOriginal);

        for (int i = 0; i < bmp.Width; i++)
        {
            for (int j = 0; j < bmp.Height; j++)
            {
                //获得原来像素点颜色
                Color c = bmp.GetPixel(i, j);
                //改变
                int gray = (c.R + c.G + c.B) / 3;
                Color cAfter = Color.FromArgb(gray ,gray ,gray );
                //设置回去
                bmp.SetPixel(i, j, cAfter);
            }
        }
        picAfter.BackgroundImage = bmp;
    }

    private void btnSave_Click(object sender, EventArgs e)
    {
        //保存图片
        SaveFileDialog sfd = new SaveFileDialog();
        sfd.ShowDialog();

        picAfter.BackgroundImage.Save (sfd .FileName +".bmp");
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void pictureBox1_Click(object sender, EventArgs e)
    {

    }


    private void button3_Click(object sender, EventArgs e)
    {            //以浮雕效果显示图像
        try
        {
            int Height = this.pictureBox1.BackgroundImage.Height;
            int Width = this.pictureBox1.BackgroundImage.Width;
            Bitmap newBitmap = new Bitmap(Width, Height);
            Bitmap oldBitmap = (Bitmap)this.pictureBox1.BackgroundImage;
            Color pixel1, pixel2;
            for (int x = 0; x < Width - 1; x++)
            {
                for (int y = 0; y < Height - 1; y++)
                {
                    int r = 0, g = 0, b = 0;
                    pixel1 = oldBitmap.GetPixel(x, y);
                    pixel2 = oldBitmap.GetPixel(x + 1, y + 1);
                    r = Math.Abs(pixel1.R - pixel2.R + 128);
                    g = Math.Abs(pixel1.G - pixel2.G + 128);
                    b = Math.Abs(pixel1.B - pixel2.B + 128);
                    if (r > 255)
                        r = 255;
                    if (r < 0)
                        r = 0;
                    if (g > 255)
                        g = 255;
                    if (g < 0)
                        g = 0;
                    if (b > 255)
                        b = 255;
                    if (b < 0)
                        b = 0;
                    newBitmap.SetPixel(x, y, Color.FromArgb(r, g, b));
                }
            }
            this.picAfter.BackgroundImage = newBitmap;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

    }

    private void button4_Click(object sender, EventArgs e)
    {
        //以锐化效果显示图像
        try
        {
            int Height = this.pictureBox1.BackgroundImage.Height;
            int Width = this.pictureBox1.BackgroundImage.Width;
            Bitmap newBitmap = new Bitmap(Width, Height);
            Bitmap oldBitmap = (Bitmap)this.pictureBox1.BackgroundImage;
            Color pixel;
            //拉普拉斯模板
            int[] Laplacian = { -1, -1, -1, -1, 9, -1, -1, -1, -1 };
            for (int x = 1; x < Width - 1; x++)
                for (int y = 1; y < Height - 1; y++)
                {
                    int r = 0, g = 0, b = 0;
                    int Index = 0;
                    for (int col = -1; col <= 1; col++)
                        for (int row = -1; row <= 1; row++)
                        {
                            pixel = oldBitmap.GetPixel(x + row, y + col); r += pixel.R * Laplacian[Index];
                            g += pixel.G * Laplacian[Index];
                            b += pixel.B * Laplacian[Index];
                            Index++;
                        }
                    //处理颜色值溢出
                    r = r > 255 ? 255 : r;
                    r = r < 0 ? 0 : r;
                    g = g > 255 ? 255 : g;
                    g = g < 0 ? 0 : g;
                    b = b > 255 ? 255 : b;
                    b = b < 0 ? 0 : b;
                    newBitmap.SetPixel(x - 1, y - 1, Color.FromArgb(r, g, b));
                }
            this.picAfter.BackgroundImage = newBitmap;
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "信息提示");
        }
    }
}

}

EEE
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Damoncreater
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//定义绘图对象
Graphics g;

    int dashOffset;
    private void Form1_Paint(object sender, PaintEventArgs e)
    {

    }

    Point clickPoint;
    int w;
    int h;

    bool isDrawRect;
    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {

    }

    private void Form1_MouseMove(object sender, MouseEventArgs e)
    {

    }


    private void Form1_MouseUp(object sender, MouseEventArgs e)
    {

    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        dashOffset++;
        this.Invalidate();
    }

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        //实例化绘图对象
        g = e.Graphics;

        Pen pen = new Pen(Color.Black, 2);
        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
        pen.DashPattern = new float[] { 4, 4 };
        pen.DashOffset = dashOffset;

        //画一个矩形
        g.DrawRectangle(pen, clickPoint.X, clickPoint.Y, w, h);

        Pen pen2 = new Pen(Color.White, 2);
        pen2.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
        pen2.DashPattern = new float[] { 4, 4 };
        pen2.DashOffset = dashOffset + 4;

        //画一个矩形
        g.DrawRectangle(pen2, clickPoint.X, clickPoint.Y, w, h);

    }
    private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
    {
        isDrawRect = true;
        clickPoint = new Point(e.X, e.Y);
    }


    private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
    {
        if (isDrawRect)
        {

            w = e.X - clickPoint.X;
            h = e.Y - clickPoint.Y;

            g = pictureBox1.CreateGraphics();

            Pen pen = new Pen(Color.Black, 2);
            pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
            pen.DashPattern = new float[] { 4, 4 };
            pen.DashOffset = dashOffset;

            //画一个矩形
            g.DrawRectangle(pen, clickPoint.X, clickPoint.Y, w, h);

            Pen pen2 = new Pen(Color.White, 2);
            pen2.DashStyle = System.Drawing.Drawing2D.DashStyle.Custom;
            pen2.DashPattern = new float[] { 4, 4 };
            pen2.DashOffset = dashOffset + 4;

            //画一个矩形
            g.DrawRectangle(pen2, clickPoint.X, clickPoint.Y, w, h);

        }
    }

    private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
    {
        isDrawRect = false;
        //矩形头像
        Bitmap bmp = new Bitmap(w, h);
        for (int i = 0; i < w; i++)
        {
            for (int j = 0; j < h; j++)
            {
                Color c = bmpOriginal.GetPixel(i + clickPoint.X, j + clickPoint.Y);
                bmp.SetPixel(i, j, c);
            }
        }
        pictureBox2.BackgroundImage = bmp;
        //圆形头像

    }
    //打开图片文件
    Bitmap bmpOriginal;
    private void button1_Click(object sender, EventArgs e)
    {
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.ShowDialog();

        string imgFileName = ofd.FileName;

        bmpOriginal = new Bitmap(imgFileName);

        pictureBox1.BackgroundImage = bmpOriginal;
    }



    private void pictureBox2_Click(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {
        //保存图片
        SaveFileDialog sfd = new SaveFileDialog();
        sfd.ShowDialog();

        pictureBox2.BackgroundImage.Save(sfd.FileName + ".bmp");
    }

}

}

FFF
1) using System;
2) using System.Collections.Generic;
3) using System.ComponentModel;
4) using System.Data;
5) using System.Drawing;
6) using System.Linq;
7) using System.Text;
8) using System.Windows.Forms;
9) using System.Drawing.Drawing2D;
10)
11) namespace Geometry_
12) {
13) public partial class Form1 : Form
14) {
15) public Form1()
16) {
17) InitializeComponent();
18) }
19) List

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Geometry_
{
//几何图源的父类
class ParentGeometry
{
public Color frameColor;//边框颜色
//int framewidth;
//public DashStyle frameDashStyle;
public Color fillColor;//填充颜色
//public Rectangle rectBox;
//绘制
public virtual void Draw(Graphics g) { }
}
//矩形
class MyRectangle : ParentGeometry {
public Rectangle rect;
//绘制
public override void Draw(Graphics g) {
Pen pen = new Pen(frameColor, 3);
SolidBrush sb = new SolidBrush(fillColor);
g.DrawRectangle(pen, rect);
g.FillRectangle(sb, rect);
}
}
//椭圆
class MyEllipse : ParentGeometry
{
public Rectangle rect;
//绘制
public override void Draw(Graphics g)
{
Pen pen = new Pen(frameColor, 3);
SolidBrush sb = new SolidBrush(fillColor);
g.DrawEllipse(pen, rect);
g.FillEllipse(sb, rect);
}
}
//三角形
class MyTriangle : ParentGeometry
{
public Rectangle rect;
public override void Draw(Graphics g)
{
Point[] points = new Point[3];
//描绘三角形的三个点的坐标
points[0] = new Point(rect.X + rect.Width / 2, rect.Y);//顶点坐标o
points[1] = new Point(rect.X, rect.Height + rect.Y);
points[2] = new Point(rect.X + rect.Width, rect.Height + rect.Y);
Pen pen = new Pen(frameColor, 3);
g.DrawPolygon(pen, points);
SolidBrush sb = new SolidBrush(fillColor);
g.FillPolygon(sb, points);
}
}
//自由曲线
class MyFreeLine : ParentGeometry {
public List

    public override void Draw(Graphics g)
    {
        Pen pen = new Pen(frameColor, 3);
        if (lstPolygon.Count >= 5) {
            g.DrawPolygon(pen, lstPolygon.ToArray());
        }     
    }
}
//箭头
class MyArrow : ParentGeometry {
    public Rectangle rect;      
    public override void Draw(Graphics g)
    {
        Point[] points = new Point[7];
        points[4] = new Point(rect.X + rect.Width * 3 / 4, rect.Y);
        points[6] = new Point(rect.X + rect.Width, rect.Y + rect.Height / 2);
        points[5] = new Point(rect.X + rect.Width * 3 / 4, rect.Y + rect.Height);
        points[3] = new Point(rect.X + rect.Width * 3 / 4, (rect.Y + rect.Height) * 3 / 4);
        points[1] = new Point(rect.X, (rect.Y + rect.Height) * 3 / 4);
        points[0] = new Point(rect.X, (rect.Y + rect.Height) / 4);
        points[2] = new Point((rect.X + rect.Width) * 3 / 4, (rect.Y + rect.Height) / 4);

        Pen pen = new Pen(frameColor, 3);
        SolidBrush sb = new SolidBrush(fillColor);            
        g.DrawPolygon(pen, points);
        g.FillPolygon(sb, points);
    }
}

}

C#桌面程序设计复习

标签:ati   iap   i++   quic   enter   lips   微软   dir   except   

原文地址:https://www.cnblogs.com/Damonblogs/p/9937236.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!