How do form paint itself ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I wrote a very simple windows form application. In my form I put a button.
Then I wire a function to the Paint event of the form. In that function, I do
nothing. I start the application from VS.Net and set a breakpoint in the
function. Everytime I hide the form and then unhide the form, the breakpoint
in my function(when the Paint event is fired) is hit. But my question is
how/when the form and button are able to paint themself though I do nothing
in the Paint event. What's the magic here?

Thanks,
Jazz
 
The windows forms system is built upon the underlying windows foundation.
The frame of the window, the titlebar and indeed any standard buttons or
controls that you have placed on your form are drawn by the win32 system.

The addditional functionality that you supply by overriding a Paint event or
creating a custom control are called for you after all the basic stuff has
already happened.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Good answer Bob, but just thought this addition might help to clarify.

Jazz,

When you create a winform that form is a class that derives
System.Windows.Form. As Paint is a method of Form, you get it for free.


Whenever Windows decides that a form must be repainted this inherited
event fires. Incidently you can request Windows to redraw a form buy
calling its Invalidate method.

Hope this helps

Simon Rigby
 
An additional note: It is best practice to override Control.OnPaint in
derived classes instead of registering for the Paint event of the base class.

Regards, Jakob.
 
Back
Top