C# GDI+ 在Panel中绘制直线,总是出现直线重复的问题!
privatevoidpictureBox1_MouseDown(objectsender,MouseEventArgse){if(e.Button==MouseButt...
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
IsDraw = true;
StartPoint = new Point(e.X, e.Y);
}
else
{
Graphics g = this.pictureBox1.CreateGraphics();
g.Clear(this.BackColor);
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
this.Text = string.Format("X:{0},Y:{1}", e.X, e.Y);
if (IsDraw)
{
Graphics g = null;
pen = new Pen(color, 1);
EndPoint = new Point(e.X, e.Y);
g = this.pictureBox1.CreateGraphics();
Point newPoint = new Point(StartPoint.X, StartPoint.Y);
g.DrawLine(pen, StartPoint, EndPoint);
g.Dispose();
pen.Dispose();
}
reDraw(finishImg);
}
常用GDI的朋友帮忙看看怎么回事 展开
{
if (e.Button == MouseButtons.Left)
{
IsDraw = true;
StartPoint = new Point(e.X, e.Y);
}
else
{
Graphics g = this.pictureBox1.CreateGraphics();
g.Clear(this.BackColor);
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
this.Text = string.Format("X:{0},Y:{1}", e.X, e.Y);
if (IsDraw)
{
Graphics g = null;
pen = new Pen(color, 1);
EndPoint = new Point(e.X, e.Y);
g = this.pictureBox1.CreateGraphics();
Point newPoint = new Point(StartPoint.X, StartPoint.Y);
g.DrawLine(pen, StartPoint, EndPoint);
g.Dispose();
pen.Dispose();
}
reDraw(finishImg);
}
常用GDI的朋友帮忙看看怎么回事 展开
2个回答
展开全部
出现直线重复?
如果是我,我会自己派生一个类来弄
public class MyPictureBox : PictureBox
{
override void OnMouseDown...
override void OnMouseMove...
override void OnPaint()
{
....
}
}
这样更能自己控制,双缓冲,先画到Bitmap再一次性画到控件上,防闪烁
或者你的 g.Clear(this.BackColor); 放的位置不太对,你到底有几条直线,需要保留原图,在原图基础上画吗?也就是原来划过直线的基础上再画新的第二条,第三条直线,否则如果只有一条直线的话,你干嘛不在画直线之前一行,g.Clear(this.BackColor);
更多追问追答
追问
在问一个问题 为嘛我的PictureBox中放一张图片后 画线就把图给我删除掉了 我晕
追答
g.Clear(this.BackColor);清楚掉了
这里就是有个是你先画直线还是它先画它的图的时序问题
你只能 public class MyPictureBox : PictureBox 来弄了
每次画的时候
g.Clear(this.BackColor);
g.DrawImage 你的图片
g.DrawLine 你的直线
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询