绘制直线的重绘问题
我在做一个简单的画板,做到了绘制知道的地方,但是再画第二次直线的时候就会把前面的一条直线给擦掉,请问谁有关于直线重绘的代码,帮忙给我介绍一下呀,急需! --------------------编程问答-------------------- 你没说你用什么方法绘制的,如果可以,请贴出关键代码 --------------------编程问答-------------------- private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e){
if (drawing)
{
Graphics g = this.pictureBox1.CreateGraphics();
Pen backPen = new Pen(this.pictureBox1.BackColor);
g.DrawLine(backPen, this.start, this.end);
this.end.X = e.X;
this.end.Y = e.Y;
Pen forePen = new Pen(Color.Blue);
g.DrawLine(forePen, this.start, this.end);
}
}
private void pictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (drawing)
{
Graphics g = this.pictureBox1.CreateGraphics();
Pen backPen = new Pen(this.pictureBox1.BackColor);
g.DrawLine(backPen, this.start, this.end);
this.end.X = e.X;
this.end.Y = e.Y;
Pen forePen = new Pen(Color.Blue);
g.DrawLine(forePen, this.start, this.end);
this.drawing = false;
this.drawing = false;
array.Add(new Rectangle(this.start, new Size(this.width, this.height)));
}
}
这是我做的关于mousemove和mouseup的代码 --------------------编程问答--------------------
每次都CreateGraphics,当然会被清除掉吧。
改用
Graphics g = Graphics.FromImage(pictureBox1.Image);
这样试试。
还有画完了别忘了g.Dispose(); --------------------编程问答-------------------- 我还是新手,这个方法不懂,可不可以在我创建的代码的基础上写一下关于paint的重绘的代码呀?
补充:.NET技术 , C#