[GDI+] How to sync refresh

shouzama

Active member
Joined
Jan 20, 2003
Messages
38
Location
Another World
Lets suppose I have a Graphic object attached to a generic PictureBox.

If I draw something on the graphic object during the Form.Load event, nothing is actually displayed.
I know this happens because the "refresh" action on the Form (when it finally shows up) cancels everything that has been drawn on it.

To "sync" up the drawing with the refresh, I thought it was simply a matter of choosing the right event.
So, I put every "draw" into the Form.Paint event.
No results, however.
When the form loads, nothing is displayed
When the form loses and then gains focus, nothing is displayed
However, when the form is brought over the boundaries of the screen (and then back in), the picture draws correctly.

Should I put the "draw" event even in the Form.GotFocus?
Or am I missing something else?
 
Hi

Can you post the code youve got in the paint event?
I just like to see where and when you get the handle to the graphics object

Thanks
 
Currently Im at work, so I dont have the code at hand
If I remember correctly:

In the form I have
Code:
Private m_Graphics as Graphics

Then in Form.Load
Code:
m_Graphics = PictureBox1.CreateGraphics

Then in Form.Pain I have the m_Graphics do all the stuff
 
The correct way to do this is to do all your paintint in either the Paint event of the picturebox, or by overriding the OnPaint method in a derived class. Do NOT keep a graphics object around as you are doing. Insted, use the one passed as an argument to the event, e.Graphics.
 
Back
Top