Do I Have to Redraw Graphics?

J

John Baker

I am using a Graphics object to draw on a form. If I pop up a message
box, or if say the user minimizes and then restores the form, my
graphics are erased (just where the box was in the former case).

Do I have to detect these things and redraw, or is there a way to
prevent this from happening?
 
H

Herfried K. Wagner [MVP]

John Baker said:
I am using a Graphics object to draw on a form. If I pop up a message box,
or if say the user minimizes and then restores the form, my graphics are
erased (just where the box was in the former case).

Do I have to detect these things and redraw, or is there a way to prevent
this from happening?

Override your form's/control's 'OnPaint' method and perform the drawing
there.
 
J

Jay B. Harlow [MVP - Outlook]

John,
The Paint event (OnPaint method) is called each time you need to draw,
within the Paint event you want to use e.Graphics to do you drawing rather
then calling CreateGraphics directly. You do not need to displose of the
e.Graphics object, but you should dispose of other System.Drawing objects
that you may create.

The following article discusses the drawing on the form in more detail:

http://www.bobpowell.net/creategraphics.htm

The above FAQ can be entered at:

http://www.bobpowell.net/gdiplus_faq.htm

Hope this helps
Jay
 
L

Larry Serflaten

John Baker said:
I am using a Graphics object to draw on a form. If I pop up a message
box, or if say the user minimizes and then restores the form, my
graphics are erased (just where the box was in the former case).

Do I have to detect these things and redraw, or is there a way to
prevent this from happening?


That is the designed behaviour. For one way to keep the graphics
after minimizing, check out this link:

http://groups.google.com/[email protected]


LFS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top