Can't draw to a pictureBox in a loop
Posted
by
Jason94
on Stack Overflow
See other posts from Stack Overflow
or by Jason94
Published on 2010-12-23T08:43:28Z
Indexed on
2010/12/23
8:54 UTC
Read the original article
Hit count: 262
c#
I have a List<Point>
where Point contains X and Y.
What i want is to loop a list like that and draw a line point to point, i do so by:
foreach (List<Point> wps in map.waypoints)
{
System.Drawing.Pen myPen;
myPen = new System.Drawing.Pen(System.Drawing.Color.Black);
System.Drawing.Graphics formGraphics = this.pictureBox1.CreateGraphics();
Point startPos = new Point(wps[0].X, wps[0].Y);
foreach (Point p in wps)
{
formGraphics.DrawLine(myPen, startPos.X, startPos.Y, p.X, p.Y);
startPos = p;
}
myPen.Dispose();
formGraphics.Dispose();
}
BUT nothing gets drawn! I did the same with the on_click event to the pictureBox but instead if a looping some Points ive just used mouse X and Y. I have verified the lists of points that they dont contain rubish :D
© Stack Overflow or respective owner