Saturday, November 11, 2006

Raising Base Class Events From a Derived Class in .NET

I always forget how to do simple things. This blog is likely to contain lots of little snippets like this. Lots of them will be stuff that big brained techheads find fairly obvious. Well, that's just tuff. You sit in your big comfy chairs and scoff. I'm not here to feed your egos. I'm here to post stuff about things that I find hard to locate, stuff that made me smack my forehad when I found it because it was so obvious. The frustration and time wasted searching for it makes it worth posting here.

So, with that out of the way, here we go. And I'm not even going to add any fluff to it. Just a simple code sample.

Public Class BaseClass

Public Event
MyEvent(ByVal sender As Object, ByVal e As EventArgs)

Protected Sub
OnMyEvent()
RaiseEvent MyEvent(Me, EventArgs.Empty)
End Sub

End Class

Public Class DerivedClass
Inherits BaseClass

Public Sub MyTask()
MyBase.OnMyEvent() ' Raises the event
End Sub

End Class

No comments: