Although most event handlers are automatically hooked up through WithEvents
data members, it may be necessary to dynamically add and remove event handlers at runtime. The AddHandler
and RemoveHandler
statements do this.
Each statement takes two parameters: an event expression and an expression that must evaluate to a delegate instance of the appropriate type for the event hookup. Given an event E
, the statement either calls the relevant add_E
or remove_E
method on the instance to add or remove the delegate as a handler for the event. The parameters are always evaluated left to right at runtime.
AddHandler
HandlerArguments StatementTerminatorRemoveHandler
HandlerArguments StatementTerminator,
ArgumentExpression