1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| public partial class Graphique : Form
{
public Graphique()
{
InitializeComponent();
try
{
Point[] points = GetPointsFormTextFile("TextFile1.txt");
GraphicsPath gp = new GraphicsPath();
gp.AddLines(points);
Bitmap bitmap = new Bitmap(this.pictureBox1.Width, this.pictureBox1.Height);
Graphics g = Graphics.FromImage(bitmap);
g.DrawPath(SystemPens.ControlText, gp);
g.Dispose();
this.pictureBox1.Image = bitmap;
}
catch (Exception exc)
{
MessageBox.Show(exc.Message + "\r\n" + exc.StackTrace);
}
}
private Point[] GetPointsFormTextFile(string txtFile)
{
ArrayList points = new ArrayList();
PointConverter pc = new PointConverter();
StreamReader sr = File.OpenText(txtFile);
string line;
while ((line = sr.ReadLine()) != null)
{
points.Add((Point)pc.ConvertFromString(line));
}
sr.Close();
sr = null;
return (Point[])points.ToArray(typeof(Point));
}
} |
Partager