吉吉于

free

C#每天抄一点(13):画图

01 /*
02 * 由SharpDevelop创建。
03 * 用户: Lazynight
04 * 日期: 2011/10/14
05 * 时间: 19:37
06 *
07 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
08 */
09 using System;
10 using System.Collections.Generic;
11 using System.Drawing;
12 using System.Windows.Forms;
13
14 namespace Lazy13_画图
15 {
16     public partial class MainForm : Form
17     {
18         int StartX;    //    鼠标起点X坐标
19         int StartY;//  鼠标起点Y坐标
20         Graphics Lazy_pic; //定义Graphics变量
21
22         public MainForm()
23         {
24             InitializeComponent();
25         }
26         void MainFormLoad(object sender, EventArgs e)
27         {
28             this.StartPosition=FormStartPosition.CenterScreen;//初始位置居中
29             this.BackColor=Color.Snow;//设置面板背景色
30         }
31         private void MouseUp1(object sender,MouseEventArgs e)
32         {
33             Lazy_pic=this.CreateGraphics();   //创建Graphics对象
34             Pen Lazy_pen=new Pen(Color.Black,2);    //创建画笔
35             if(radioButton1.Checked==true)
36             {
37                 Lazy_pic.DrawLine(Lazy_pen,StartX,StartY,e.X,e.Y);//画线,笔,起始坐标,结束坐标
38             }
39         }
40         private void MouseDown1(object sender,MouseEventArgs e)
41         {
42             StartX=e.X;    //获取起始坐标
43             StartY=e.Y;
44         }
45         private void MouseDown2(object sender,MouseEventArgs e)
46         {
47             Lazy_pic=this.CreateGraphics();//创建Graphics对象
48             Pen Lazy_pen=new Pen(Color.Red,2);//创建画笔
49             if (radioButton2.Checked==true)
50             {
51                 Lazy_pic.DrawRectangle(Lazy_pen,e.X,e.Y,2,2);
52             }
53         }
54         void Button1Click(object sender, EventArgs e)
55         {
56             Lazy_pic=this.CreateGraphics();
57             Lazy_pic.Clear(Color.Snow);
58         }
59     }
60 }

下载源码

转载请注明:于哲的博客 » C#每天抄一点(13):画图