hello,
i'm making a random graph generator
the coordonates are loaded from a file
i've managed to draw the points but can't manage to draw the lines between these points
here's the code
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Refresh();
gr = pictureBox1.CreateGraphics();
SolidBrush redBrush = new SolidBrush(Color.Red);
int p1h = pictureBox1.Size.Height;
int p1w = pictureBox1.Size.Width;
gr.DrawLine(Pens.Black, 0, p1h / 2, p1h, p1w / 2);
gr.DrawLine(Pens.Black, p1h / 2, 0, p1h / 2, p1w);
gr.DrawLine(Pens.Black, p1h / 2, 0, p1h / 2 - 5, 10);
gr.DrawLine(Pens.Black, p1h / 2, 0, p1h / 2 + 5, 10);
gr.DrawLine(Pens.Black, p1w, p1h / 2, p1h - 10, p1w / 2 + 5);
gr.DrawLine(Pens.Black, p1w, p1h / 2, p1h - 10, p1w / 2 - 5);
string filePath = path + @"\coordonate.txt";
string line;
char[] separatori = new char[] { ' ', '\n' };
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
while ((line = sr.ReadLine()) != null)
{
for (int i1 = 0; i1 < line.Length-1; i1++)
{
coord[i1] = line.Split(separatori);
for (int i = 0; i < coord[i1].Length; i++)
{
float x1 = (float)Convert.ToDouble(coord[i1][0]);
float y1 = (float)Convert.ToDouble(coord[i1][1]);
gr.FillEllipse(redBrush, x1 * p1h, y1 * p1h, 5, 5);
gr.DrawLine(Pens.Red, ...............);
}
}
}
sr.Close();
}
the file looks like this (all numbers are random)
-0.97 -0.58
1.00 0.21
0.97 0.59
-0.46 -0.20
-0.17 -0.10
0.59 0.78
0.16 0.43
-0.12 0.01
0.17 0.28
-0.04 -0.53
-0.51 -0.82
0.18 0.49
-0.69 0.61
0.68 -0.32
0.97 -0.30
0.79 -0.44
-0.60 0.16
0.15 -0.81
0.80 -0.60
when i run this code on this line
coord[i1] = line.Split(separatori);
i get : Object reference not set to an instance of an object.
thanks