shouzama Posted February 5, 2003 Posted February 5, 2003 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? Quote
Cywizz Posted February 5, 2003 Posted February 5, 2003 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 Quote Howzit??
shouzama Posted February 5, 2003 Author Posted February 5, 2003 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 Quote
*Gurus* divil Posted February 5, 2003 *Gurus* Posted February 5, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
shouzama Posted February 5, 2003 Author Posted February 5, 2003 Thanks a lot Divil, I'll try and let you know! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.