James,
Is MyControl the name of the user control?
In addition to what OHM stated.
..NET does not allow a derived class from invoking a base event. Hence if you
wanted to raise the Paint event in your code you would not be able to. Yes
Yes, you should really use Invalidate & Update or Refresh on a form to cause
the Paint event to be raised, but bear with me. ;-)
So the pattern in .NET is to have an event MyEvent and an overridable method
OnMyEvent. The OnMyEvent when called will raise the MyEvent of the base.
Because its overridable derived classes can choose to do something before or
after calling the base class's OnMyEvent... Like replacing the event args
with a class derived from the normal event args adding addition
information...
Also, overriding a method is generally quicker than handling an event, at
least cleaner. So overriding the OnPaint method should perform better than
handling the Paint event, especially if there are other handlers of said
event...
The most important thing about overriding the OnPaint method (especially the
OnPaint) is to call the base class's OnPaint.
I think of it this way:
The OnPaint method is for notification internal to the object (the class,
classes I derive from, and classes that derive from me).
The Paint event is for notification external to the object (other objects).
In your example, I would override the OnEnter method, being sure to call
MyBase.OnEnter within my MyControl user control.
For example, when I design a form I normally override the OnLoad method,
instead of handling the MyBase.Load event (as the designer would have you
do).
Hope this helps
Jay
"James Ramaley" <jr******@iname.com> wrote in message
news:f8**************************@posting.google.c om...
I have created a VB.NET User Control which inherits from TextBox. I
have a general question regarding how functionality should be
overwritten:
I can either write a method which handles an event:
function MyControl_Enter(...) handles MyControl.Enter
or I can overwrite the relevant virtual method:
function overwrites onEnter(...)
Are these two ways of doing the same thing? When should I use the
first approach, and when the other?
Thanks for helping me understand this.