各位大佬,麻烦帮我看看哪里不对劲,根据MouseDowm、MouseMove、MouseUp画下直线,但再画另一条之前画的一条就消失了。请教怎么画多条直线?只画直线就行
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if(startDraw)
{
startpoint.X=e.X;
startpoint.Y= e.Y;
sdraw = true;
}
}
private void button3_Click(object sender, EventArgs e)
{
startDraw = false;
}
private void button1_Click_1(object sender, EventArgs e)
{
startDraw = true;//点击按钮鼠标处于画线状态
}
private void panel1_MouseUp(object sender, MouseEventArgs e)
{
if (startDraw)
{
sdraw = false ;
}
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (startDraw)
{
if (sdraw)
{
currentpoint.X = e.X;
currentpoint.Y = e.Y;
Refresh();
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics newgraphics = e.Graphics;
Rectangle r = new Rectangle(0, 0, 795, 400);//是创建画矩形的区域
newgraphics.DrawRectangle(Pens.Red, r);
if (sdraw && startDraw)
{
newgraphics.DrawLine(p, startpoint, currentpoint);
}
}