Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Drawing / May 2004

Tip: Looking for answers? Try searching our database.

What is the purpose of OnPaint?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kjon - 30 May 2004 06:57 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.