S
Steve
Hey,
I would like to create some random data points at program start (preferably
not with a mouse click or some other user event) and then draw them on a
form. But if I create the points in the Paint event handler, it
reinitializes and redraws the points every time I resize the form (see
below). How can I create one set of points and then simply pass them to
OnPaint? Thanks for your help. Steve
public void OnPaint(object obj, PaintEventArgs e)
{
Graphics g = e.Graphics;
Random num = new Random();
Point[] points = new Point[500];
for (int i=0; i<points.GetLength(0); i++)
{
points.X = i;
points.Y = num.Next(0, 200);
}
Pen pen = new Pen(Color.Green);
g.DrawLines(pen, points);
}
I would like to create some random data points at program start (preferably
not with a mouse click or some other user event) and then draw them on a
form. But if I create the points in the Paint event handler, it
reinitializes and redraws the points every time I resize the form (see
below). How can I create one set of points and then simply pass them to
OnPaint? Thanks for your help. Steve
public void OnPaint(object obj, PaintEventArgs e)
{
Graphics g = e.Graphics;
Random num = new Random();
Point[] points = new Point[500];
for (int i=0; i<points.GetLength(0); i++)
{
points.X = i;
points.Y = num.Next(0, 200);
}
Pen pen = new Pen(Color.Green);
g.DrawLines(pen, points);
}