Event of BaseClass

  • Thread starter Halimaji Nijazi
  • Start date
H

Halimaji Nijazi

Hi newsgroup

I am creating a Mustinheritable Class. From this class I inherit several
other classes.

Now I like to interit the events to, but I can't do this. What am I doing
wrong.

Here is a simple code as sample:

Public MustInherit Class test

Public MustOverride Function testFunct() As Boolean

Public Event testevent()

End Class

Public Class test2

Inherits test

Public Overrides Function testFunct() As Boolean

End Function

End Class


I only want to use the event from the base class, but don't know how...


Thanks for the help...

Regards

Nijazi Halimaji
 
C

ClayB

Most .NET framework classes have event pattern that provides for a
protected virtual method (OnXXXXX) that actually raises the event
(XXXXX). So, for example, the event Control.MouseDown is actually
raised within the library method Control.OnMouseDown which is
protected and virtual. So, in your classes, you could use the same
pattern. You could expose a virtual method that actually raises your
event. Then the inheritors of your class can interact and control the
event through an override.

==============
Clay Burch
Syncfusion, Inc.
 
P

Phill W.

Halimaji said:
Hi newsgroup

I am creating a Mustinheritable Class. From this class I inherit several
other classes.

Now I like to interit the events to, but I can't do this. What am I doing
wrong.

You /do/ inherit the Events but you /can't/ raise them directly from
within a derived class.

The design pattern from Our Friends in Redmond is (as far as I
understand it) to provide a Protected method that raises the event on
behalf of any subclasses, something like:

Public MustInherit Class test

Public MustOverride Function testFunct() As Boolean

Public Event TestEvent( _
ByVal sender As Object _
, ByVal e as EventArgs _
)

Protected Sub OnTestEvent()
RaiseEvent TestEvent( Me, EventArgs.Empty )
End Sub

End Class

Public Class test2
Inherits test

Public Overrides Function testFunct() As Boolean
MyBase.OnTestEvent()
End Function

End Class

HTH,
Phill W.
 

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

Top