码迷,mamicode.com
首页 > 其他好文 > 详细

在控件内实现简单画笔功能

时间:2017-08-30 13:01:01      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:ict   class   send   ons   get   rgs   draw   down   handler   

/// <summary>
/// 实现窗体内简单画笔功能
/// </summary>
public class DrawClass
{
private Color __Color = new Color();
private Point __Start = new Point();
private Point __End = new Point();
private Form __frmMain = new Form();
private PictureBox __picMain = new PictureBox();
private Graphics __g = null;
private Pen __p = null;

public Color Color
{
get { return this.__Color; }
set { this.__Color = value; }
}
public Point Start
{
get { return this.__Start; }
set { this.__Start = value; }
}
public Point End
{
get { return this.__End; }
set { this.__End = value; }
}


public DrawClass(Form frmMain)
: this(frmMain, Color.Black)
{ }
public DrawClass(PictureBox picMian)
: this(picMian, Color.Red)
{ }

public DrawClass(Form frmMain, Color c)
{
this.__frmMain = frmMain;
this.__g = Graphics.FromHwnd(frmMain.Handle);
this.__Color = c;
this.__p = new Pen(this.__Color,2);
this.__frmMain.MouseDown += new MouseEventHandler(__frmMain_MouseDown);
this.__frmMain.MouseMove += new MouseEventHandler(__frmMain_MouseMove);
this.__frmMain.MouseUp += new MouseEventHandler(__frmMain_MouseUp);
}

public DrawClass(PictureBox frmMain, Color c)
{
this.__picMain = frmMain;
this.__g = Graphics.FromHwnd(frmMain.Handle);
this.__Color = c;
this.__p = new Pen(this.__Color,2);
this.__picMain.MouseDown += new MouseEventHandler(__frmMain_MouseDown);
this.__picMain.MouseMove += new MouseEventHandler(__frmMain_MouseMove);
this.__picMain.MouseUp += new MouseEventHandler(__frmMain_MouseUp);
}

private void __frmMain_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
__End.X = e.X;
__End.Y = e.Y;
__g.DrawLine(this.__p, __Start, __End);
__Start = __End;
}
}

private void __frmMain_MouseUp(object sender, MouseEventArgs e)
{

}

private void __frmMain_MouseDown(object sender, MouseEventArgs e)
{
this.__Start.X = e.X;
this.__Start.Y = e.Y;
}


}

 

DrawClass draw = new ZhuoHuiClass.DrawClass(this.pic);                              //调用画笔功能

 

在控件内实现简单画笔功能

标签:ict   class   send   ons   get   rgs   draw   down   handler   

原文地址:http://www.cnblogs.com/Mzg121584668/p/7452360.html

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