Hi, I'm new to the GDI graphics programming and would like to know what's
the real purpose of the overridable OnPaint event?
I mean, I have tried to draw something on my control in a normal sub and it
still can draw when I call the sub in the program without going through
OnPaint. This also happen when I call the sub in the control's Resize event.
So should I use (or advisable to use) the OnPaint event to do ANY drawing?
When is OnPaint really fire? And will it affect the performance? Thanks.
Regards,
KJon
Daniel - 30 May 2004 07:39 GMT
All your drawing should be done in OnPaint/Paint event handler. Drawing
with CreateGraphics() is not good practice and things call dissapear when
resized etc.
Dan
> Hi, I'm new to the GDI graphics programming and would like to know what's
> the real purpose of the overridable OnPaint event?
[quoted text clipped - 6 lines]
> Regards,
> KJon
Bob Powell [MVP] - 30 May 2004 11:18 GMT
OnPaint is an overridable class method that is called whenever the display
needs to be refreshed. Paint is an event with a specific delegate and is
called only if an event-handler is attached to it.
Generally, if you derive a class from Control or Form, you should override
the OnPaint event to do your painting. Be sure to call the base-class if you
want the Paint event to be raised. This gives people who use your class
without deriving from it to do some painting after yours is complete.
If you're new to GDI+ I suggest that you browse the GDI+ FAQ for information
that will be helpful.

Signature
Bob Powell [MVP]
Visual C#, System.Drawing
Image transition effects, automatic persistent configuration and
design time mouse operations all in April's issue of Well Formed
http://www.bobpowell.net/wellformed.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm
The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://royo.is-a-geek.com/siteFeeder/GetFeed.aspx?FeedId=41
> Hi, I'm new to the GDI graphics programming and would like to know what's
> the real purpose of the overridable OnPaint event?
[quoted text clipped - 6 lines]
> Regards,
> KJon