I need to draw 100 lines between 100 semi-random points in a 800×800 pixel square on the screen.
I’ve been using the built-in drawlines & drawrecangles functions inside of .NET, but my drawing gets erased everytime the form paints.
So, I’ve been thinking about perhaps drawing to an in-memory bitmap, but I’m not sure if that’s a good solution.
Any tips?
Not only is this a good idea, but also it has a name (double buffering). Do your drawing on a form-level Bitmap, and then in your form’s Paint event (actually it would be better to do this with a PictureBox on the form, and use it’s Paint event) use the DrawImage method of the Graphics object to draw your Bitmap into the PictureBox.
A simpler way is just to create your Bitmap, draw on it, and then set the Bitmap as your PictureBox’s Image property. This will automatically persist the image even when your form is repainted.