user interface - Getting points from a .txt file and plotting them in a picturebox in C# -


i'm trying build windows form application in read comma separated list .txt file , plot using drawline function. code keeps getting stuck in infinite loop , i'm not sure how should proceed further. have no preference of how should plot , reason i'm using drawline function because don't know of other way i'm open other ideas might better suited doing task.

       private void starttoolstripmenuitem_click(object sender, eventargs e)     {         streamreader sr = new streamreader("../../sample.txt");         string[] values = null;         zee1 = sr.readline();         while (zee1 != null)         {             values = zee1.split(',');             x1 = int32.parse(values[0]);             x2 = int32.parse(values[1]);             y1 = int32.parse(values[2]);         }            //backgroundbitmap.save("result.jpg"); //test if ok         point point1 = new point(int.parse(values[0]), int.parse(values[2]));         point point2 = new point(int.parse(values[1]), int.parse(values[2]));          picturebox1.enabled = true;         g = picturebox1.creategraphics();         g.drawline(pen1, point1, point2);     } 

please note i'm trying plot 2 different values of x on same plot same values of y. values[0] array contains data in first column of .txt file , forth values[1] , values[2].

the txt file i'm using follows

0,4,0

1,2,1

2,1,2

3,6,3

4,1,4

5,3,5

6,8,6

you're in infinite while loop because condition never changes. need update zee1. popular way update in condition:

while ((zee1 = sr.readline()) != null) {     // here } 

it seems if want draw set of line segments (i assume 1 next), so:

private void starttoolstripmenuitem_click(object sender, eventargs e) {     list<point> points = new list<point>();     using (streamreader sr = new streamreader("../../sample.txt"))     {         string[] values = null;         while ((zee1 = sr.readline()) != null)         {             values = zee1.split(',');             points.add(new point(int.parse(values[0]), int.parse(values[2])));         }     }      picturebox1.enabled = true;     g = picturebox1.creategraphics();     (int = 0; < points.count - 1; i++)         g.drawline(pen1, points[i], points[i+1]); } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -