In C#, I could do something like this:
EventHandler handler = this.SomeEvent;
...which would allow me to, for example, do:
Delegate[] attachedHandlers = handler.GetInvocationList();
In VB.NET, I can't seem to figure out how to do a similar thing.
This doesn't work:
Dim handler As EventHandler = Me.SomeEvent
...due to the following error:
Public Event SomeEvent(sender As Object, e As EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
But this doesn't work either:
Dim handler As EventHandler = AddressOf Me.SomeEvent
...because:
'AddressOf' operand must be the name of a method (without parentheses).
So how can I actually get an EventHandler
from an event in VB.NET? The only idea that's immediately coming to mind is to use reflection, but that seems pretty ridiculous.
The EventHandler delegate is a predefined delegate that specifically represents an event handler method for an event that does not generate data. If your event does generate data, you must use the generic EventHandler<TEventArgs> delegate class.
The standard signature of an event handler delegate defines a method that does not return a value. This method's first parameter is of type Object and refers to the instance that raises the event. Its second parameter is derived from type EventArgs and holds the event data.
In programming, an event handler is a callback routine that operates asynchronously once an event takes place. It dictates the action that follows the event. The programmer writes a code for this action to take place. An event is an action that takes place when a user interacts with a program.
If you want to pass a parameter to the click event handler you need to make use of the arrow function or bind the function. If you pass the argument directly the onClick function would be called automatically even before pressing the button.
Private Event MyEvent()
Private delegates() As System.Delegate = MyEventEvent.GetInvocationList()
undocumented, found here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With