خط بین a , b کشیده میشود
private bool b; private Point p1 = new Point(); private Point p2 = new Point(); private bool bp1 = true;
private bool bp2 = false;
private void button1_Click(object sender, EventArgs e)
{
b = true;
Form9_Paint(null, new PaintEventArgs(CreateGraphics(),this.Bounds ));
}
private void Form9_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(new Pen(Color.Red), new Point(100, 100), new Point(100, 300));
e.Graphics.DrawLine(new Pen(Color.Blue), new Point(200, 100), new Point(200, 400));
e.Graphics.DrawLine(new Pen(Color.Brown), new Point(300, 100), new Point(300, 500));
if (b)
{
e.Graphics.DrawLine(new Pen(Color.YellowGreen ), p1, p2 );
}
}
private void Form9_MouseClick(object sender, MouseEventArgs e)
{
if (bp1)
{
p1.X = e.Location.X;
p1.Y = e.Location.Y;
bp1 = false;
bp2 = true;
return;
}
if (bp2)
{
p2.X = e.Location.X;
p2.Y = e.Location.Y;
bp1 = true ;
bp2 =false ;
}
}