我用GDI+中 g.drawline()的方法实现了点击鼠标左键移动画线 松开左键画线结束
我想再实现把刚画过的线删除 如何实现呢最好是像一些阅读软件 比如CAJViewer一样 在刚画过的线的旁边点击鼠标右键 选右键菜单中的删除该线
然后删除
大家有没有好的办法
我想再实现把刚画过的线删除 如何实现呢最好是像一些阅读软件 比如CAJViewer一样 在刚画过的线的旁边点击鼠标右键 选右键菜单中的删除该线
然后删除
大家有没有好的办法
ControlPaint.DrawReversibleFrame
ControlPaint.DrawReversibleLine
http://www.msproject.cn/Document/DrawTools.html
第二步,用一定的数据结构保存好你要话的线,比如一个点集(可以用List的),然后根据这个点集把线画上去。
第三步,要删除的时候,先把这个点集从你的内存中释放,然后擦除整个图画(Control.Invalidate()是控件重绘函数,在Paint事件里面写你的重绘代码),重绘你的所有需要的元素。
至于画图就用Graphics好了
来个比较好的。看看吧。
能不能给个简单的程序啊
谢谢拉
下面是我的部分程序
private void MsMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
ArrayList array = new ArrayList();
g.DrawLine(new Pen(Color.Red), oldX, oldY, e.X, e.Y);
oldX = e.X;
oldY = e.Y;
p = new Point(e.X,e.Y);
array.Add(p);
}
怎么用你的办法做到呢
你说的原理我懂了 可是我不知道怎么写程序 帮帮忙
能不能给个简单的程序啊
谢谢拉
下面是我的部分程序
private void MsMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
ArrayList array = new ArrayList();
g.DrawLine(new Pen(Color.Red), oldX, oldY, e.X, e.Y);
oldX = e.X;
oldY = e.Y;
p = new Point(e.X,e.Y);
array.Add(p);
}
怎么用你的办法做到呢
你说的原理我懂了 可是我不知道怎么写程序 帮帮忙
从mousedown到mouseup视为一次画线,把这次画线存进GraphicsPath,
第一次画的GraphicsPath存进array,那么array就是你画的那些线了。
GraphicsPath gp;
int x, y;
private void Form2_MouseDown(object sender, MouseEventArgs e)
{
x = e.X;
y = e.Y;
if (gp != null)
list.Add(gp);
gp = new GraphicsPath();
} private void Form2_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return; gp.AddLine(x, y, e.X, e.Y); x = e.X;
y = e.Y; this.Refresh();
} private void Form2_Paint(object sender, PaintEventArgs e)
{
if (gp == null)
return;
for (int i=0; i<list.Count; i++)
e.Graphics.DrawPath(Pens.Red, (GraphicsPath)list[i]); e.Graphics.DrawPath(Pens.Red, gp);
}
//list保存了每一条线,要删哪一条就指定下标。