Graphics gr;
public Form1()
{
InitializeComponent();
}
private Point p1, p2;
List<point> p1List = new List<point>();
List<point> p2List = new List<point>();
private void Form1_Paint_1( object sender, PaintEventArgs e )
{
}
private void Form1_MouseDown_1(object sender, MouseEventArgs e)
{
gr = this.CreateGraphics();
int x = e.X;
int y = e.Y;
// Create pen.
Pen whitePen = new Pen(Color.Blue, 3);
Pen red = new Pen(Color.Red, 3);
SolidBrush whiteBrush = new SolidBrush(Color.Blue);
// Create rectangle for ellipse.
Rectangle rect = new Rectangle(x - 5, y - 5, 10, 10);
gr.DrawEllipse(whitePen, rect);
gr.FillEllipse(whiteBrush, rect);
if (p1.X == 0)
{
p1.X = e.X;
p1.Y = e.Y;
}
else
{
<pre lang="c#">
p2.X = e.X;
p2.Y = e.Y;
p1List.Add(p1);
p2List.Add(p2);
using (var p = new Pen(Color.Blue, 4))
{
for (int i = 0; i < p1List.Count; i++)
{
gr.DrawLine(p, p1List[i], p2List[i]);
}
}
p1.X = 0;
}
}
this might help you