Joe,
This isn't the neatest way of doing it (especially with the Form.Load
Event). For example, if you need to catch the Form Load event in both the
base class and the derived class, you are relying on the derived class
calling MyBase.Form_Load.
IMHO, a better way of catching the Form.Load event in both the base class
and derived class would be:
--------------------------------
*Base Form*
Private Sub Form_Load(sender as object, e as EventArgs) handles MyBase.Load
' Do stuff to initialize base form.
End Sub
*Derived Form*
Private Sub Form_Load(sender as object, e as EventArgs) handles MyBase.Load
' Do stuff to initialize derived form.
End Sub
--------------------------------
Notice that the event handler in both forms is declared with *private*
scope. This will prevent the derived class from overriding the base classes
event handler and being called twice.
If you don't need to catch the Form.Load event in the base class, simply
omit the event handler. This way, child classes can catch the event as
normal.
Hope this helps,
Trev.
"Joe Fallon" <jf******@nospamtwcny.rr.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I just went through something similar.
In the Base form I double clicked a button control and got the stub with
the event handler on the end of it.
In the child form I "saved some time" by copying the stub from the Base
form and accidentally included the event handler. Then I changed it to
Overrides instead of Overridable.
Anyway the event code ran twice! What a pill finding that one was.
Bottom line - just put the event in the Base form and override it in the
child.
e.g.
Base Form:
Protected Overridable Sub frmSelectBase_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Override this method in child classes. Do NOT include an Event
Handler in the child class - or it will run twice!
End Sub
Child form:
Protected Overrides Sub frmSelectBase_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs)
'note the lack of event handler (Handles MyBase.Load)
'do stuff here
End Sub
--
Joe Fallon
"Chad Miller" <ch**@predictiveconcepts.com> wrote in message
news:Gd******************@twister.tampabay.rr.com. .. I currently have a base form that I inherit. The base for has a custom
event. The event will not raise threw the inherited form. I was
wondering if events work threw inheritance or should I use some other method?
--
Chad Miller
President and Director of Software Development
Predictive Concepts, Inc.
www.predictiveconcepts.com
407.327.9910