Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Let's 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?

Posted

Hi

 

Can you post the code you've got in the paint event?

I just like to see where and when you get the handle to the graphics object

 

Thanks

Howzit??
Posted

Currently I'm at work, so I don't have the code at hand

If I remember correctly:

 

In the form I have

Private m_Graphics as Graphics

 

Then in Form.Load

m_Graphics = PictureBox1.CreateGraphics

 

Then in Form.Pain I have the m_Graphics do all the stuff

  • *Gurus*
Posted
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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...