D
Dinsdale
I appreciate anyones help here. I've done a whole ton of cool things
in C# and am having difficulty expressing those things in VB.
In a program I wrote in C# (which I no longer have source for) I would
use the following line of code to dereference an event from all its
handlers:
myEvent = null;
How do I do this in VB.net 2.0? Using RemoveHandler I have to know
specifics about the EventHandler. I don't want to have to know this, I
want to dereference all the event handlers in the body of the class
that contains the event.
Class DelegateClass
Public Delegate Sub MyDelegate(ByVal sender As Object, ByVal e As
EventArgs)
Public Event MyEvent As MyDelegate
Public Sub OnMyEvent()
RaiseEvent MyEvent(Me, Nothing)
End Sub
Public Sub Close()
'***REMOVE ALL HANDLERS HERE***
End Sub
End Class
Class HandlerClass
Public Sub Func1(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine("Fire Phasers!")
Console.Read()
End Sub
Public Sub New()
End Sub
End Class
Module Module2
Public Sub Main()
Dim dc As New DelegateClass
Dim hc As New HandlerClass()
Dim meh As DelegateClass.MyDelegate = AddressOf hc.Func1
AddHandler dc.MyEvent, meh
dc.OnMyEvent()
dc.Close()
End Sub
End Module
Thanks for the help!
Cheers
Dinsdale
in C# and am having difficulty expressing those things in VB.
In a program I wrote in C# (which I no longer have source for) I would
use the following line of code to dereference an event from all its
handlers:
myEvent = null;
How do I do this in VB.net 2.0? Using RemoveHandler I have to know
specifics about the EventHandler. I don't want to have to know this, I
want to dereference all the event handlers in the body of the class
that contains the event.
Class DelegateClass
Public Delegate Sub MyDelegate(ByVal sender As Object, ByVal e As
EventArgs)
Public Event MyEvent As MyDelegate
Public Sub OnMyEvent()
RaiseEvent MyEvent(Me, Nothing)
End Sub
Public Sub Close()
'***REMOVE ALL HANDLERS HERE***
End Sub
End Class
Class HandlerClass
Public Sub Func1(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine("Fire Phasers!")
Console.Read()
End Sub
Public Sub New()
End Sub
End Class
Module Module2
Public Sub Main()
Dim dc As New DelegateClass
Dim hc As New HandlerClass()
Dim meh As DelegateClass.MyDelegate = AddressOf hc.Func1
AddHandler dc.MyEvent, meh
dc.OnMyEvent()
dc.Close()
End Sub
End Module
Thanks for the help!
Cheers
Dinsdale