Quote:[1]Posted by bsol on 19 Mar 2004 04:06 PM[/1]
Error in the article "New Object-Oriented Capabilities in VB.NET - Events"
Derived classes cannot raise base class events in VB.Net. Handle them sure, but not raise them - even if they are declared public. In order to achieve this handle the base class event and raise a derived class event instead.
B.
While it is true that VB.NET cannot directly raise events in base classes from a derived class, there is an easy workaround. BTW, in C# you can simply call an event in a base class like: base.onMyEventName(EventArgs e).
But in VB.NET you cannot use MyBase.EventName() at all. But the workaround is an easy one.
1) In the base class add an overridable sub that simply raises an event defined in the base class.
Public MustInherit Class MyClass
Protected Event MyEventName(ByVal e as EventArgs)
Protected Overridable Sub OnMyEventName(ByVal e as EventArgs)
Raiseevent MyEventName(e)
End Sub
End Class
2) In the derived class make a call to the overridable method: Me.OnMyEventName(New EventArgs). It's really just that easy. Do it all the time.
Have Fun....