Il codice che ti ho dato sostituisce un pezzetto del tuo codice:
private void prova()
{
this.pictureBox1.Image = null;
Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);
Graphics g = Graphics.FromImage(bmp);
Pen redPen = new Pen(Color.Red, 1 / g.DpiX);
redPen.Width = 2;
g.TranslateTransform(1, 1.0f);
g.PageUnit = GraphicsUnit.Pixel;
StreamReader sr = new StreamReader("TextFile1.txt");
int x = 0;
int y = 0;
int x1 = 0;
int y1 = 0;
string txt = "Disegnata linea: ({0},{1}:{2},{3})";
while (!sr.EndOfStream)
{
// ---- Qui il codice che ti ho dato io: -----
string coord = sr.ReadLine();
int ypos = coord.IndexOf('Y');
x = Convert.ToInt32(coord.Substring(1, ypos - 1));
y = Convert.ToInt32(coord.Substring(ypos + 1));
// ---- ----
g.DrawLine(redPen, x1, y1, x, y);
lbl.Text = string.Format(txt, x1, y1, x, y);
x1 = x; // x1 contiene il valore x di partenza per la prossima linea
y1 = y; // y1 contiene il valore y di partenza per la prossima linea
}
pictureBox1.Image = bmp;
lbl.Text = "Fatto.";
redPen.Dispose();
g.Dispose();
sr.Close();
sr.Dispose();
}
Luca