First add this code:
List<Point> points = new List<Point>();
On the object you are drawing on, record the OnClick event. One of the arguments must have the X and Y coordinates of the click. Add them to the array of points:
points.Add(new Point(xPos, yPos));
And finally, where you draw the lines, use this code:
if (DrawShape == 4) { Graphics G = this.CreateGraphics(); G.DrawPolygon(Pens.Black, points.ToArray()); }
EDIT:
Good, so the code above is not entirely correct. First of all, this is most likely a Click event, not an OnClick event. Secondly, to get the mouse position, you need two variables declared with an array of points,
int x = 0, y = 0;
Then we get the mouse move event:
private void MouseMove(object sender, MouseEventArgs e) { x = eX; y = eY; }
Then in the Click event:
private void Click(object sender, EventArgs e) { points.Add(new Point(x, y)); }
source share