(E-Mail Removed) wrote:
> Not sure how to ask this so I'll try a couple ways.
>
> So I have a class with an event...
>
> Public Class myClass
> Public Event SomethingsGoingOn()
.. . .
More usually, that's written as :
Public Class myClass
Public Event XHappening( sender as Object, e as EventArgs )
Public Event XHappened( sender as Object, e as EventArgs )
Protected Sub OnXHappening(e As System.EventArgs)
RaiseEvent XHappening( Me, e )
End Sub
Protected Sub OnXHappened(e As System.EventArgs)
RaiseEvent XHappened( Me, e )
End Sub
End Class
You'd often have custom EventArgs classes for each event; the *ing ones
should have a way of "cancelling" the event, the *ed ones need not have.
(that's a gross generalisation, but I've found it useful).
> Then I've got this other class with an instance of the first class
> with a handler for the event...
Public Class myOtherClass
Private _myClass As myClass
Public Sub New()
_myClass = New myClass
Controls.Add(_myClass)
AddHandler _myClass.SomethingsGoingOn, AddressOf myHandler
End Sub
Public Sub myHandler(sender as Object, e as EventArgs)
' the code here depends on what happened, depends on the
' properties of myClass
If TypeOf sender is myClass Then
With DirectCast( sender, myClass )
... use whatever properties you like here
End With
End If
End Sub
End Class
HTH,
Phill W.