So yeah,
Basically I drew something on a form using Graphics. Now if I move a window over the form the stuff I drew gets erased.
Is there a way to preserve the drawing?
(I’m using Windows.Forms)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Don’t draw to the Form from outside the Paint event handler (which is what it sounds like you may be doing).
You can either redraw the contents every time in your Paint event handler, or you can paint once to an offscreen bitmap and then just display the bitmap in your Paint handler.
The code for both is almost identical, but to draw to an offscreen bitmap you need to set up a new bitmap for the Graphics context to draw into.
Here’s an example which illustrates everything you need to do to use an offscreen bitmap to store the image. (And indeed, if you remove the offscreen-bitmap code from this example, the remaining code is how to draw in the Paint handler)