【发布时间】:2016-07-29 09:52:46
【问题描述】:
如何像windows Paint一样画一条线,单击固定第一个点,第二个点(和线)用鼠标移动,再单击一次固定线。
int x = 0, y = 0;
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
// Create the graphics object
Graphics g = CreateGraphics();
// Create the pen that will draw the line
Pen p = new Pen(Color.Navy);
// Create the pen that will erase the line
Pen erase = new Pen(Color.White);
g.DrawLine(erase, 0, 0, x, y);
// Save the mouse coordinates
x = e.X; y = e.Y;
g.DrawLine(p, 0, 0, x, y);
}
点击事件部分没问题,但是上面这个方法,擦除线其实是白线,和其他背景图重叠,之前绘制的蓝线。
有没有更易于管理的方法来实现它?谢谢
【问题讨论】:
-
您想保存生成的图像吗?
标签: c# winforms user-interface drawing gdi+