Graphics

  • Thread starter Thread starter Lore Leunoeg
  • Start date Start date
L

Lore Leunoeg

Hello

What is the difference between:
- overriding the OnPaint Method and
- using the Form_Paint event
to do graphics?

Is there a difference and what should I prefer for which aim?

Thank you
Sincerely
Lore
 
Lore said:
Hello

What is the difference between:
- overriding the OnPaint Method and
- using the Form_Paint event
to do graphics?

Is there a difference and what should I prefer for which aim?

Thank you
Sincerely
Lore

Overriding the OnPain method makes the normal painting routine not
happen. (unless you call mybase.paint) If you need to do things before
the paint happens, such as changing a font color you need to do it in
the onpaint method.

In the Paint event, this happens after the normal painting. In here you
could draw lines on the form so that every time the form repaints your
new lines get drawn. You could do this in the override after calling
mybase.paint, but for something like painting lines, the event is
prefered way.

Chris
 
Lore,
In addition to the other comments:

| What is the difference between:
| - overriding the OnPaint Method and
| - using the Form_Paint event

The standard pattern for events in .NET is to define an overridable
protected method that calls the event. So in the case of Paint. OnPaint is
the method that raises the Paint event.

Having an overridable protected method (OnPaint in this case) allows derived
classes to raise the event, plus it allows derived classes to handle the
event in specific manner, such as pre or post processing.

http://msdn.microsoft.com/library/d...s/cpgenref/html/cpconEventUsageGuidelines.asp

http://msdn.microsoft.com/library/d.../cpgenref/html/cpconEventNamingGuidelines.asp


| what should I prefer for which aim?
I use the OnPaint method for internal (within the object) notification,
while I use Paint event itself for external (outside the object)
notification. In other words if I have an object that holds a reference to a
Form, the object would handle the Paint event. While a derived Form I would
override the OnPaint method, and be certain to call MyBase.OnPaint.


--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hello
|
| What is the difference between:
| - overriding the OnPaint Method and
| - using the Form_Paint event
| to do graphics?
|
| Is there a difference and what should I prefer for which aim?
|
| Thank you
| Sincerely
| Lore
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top