Instrução AddHandler
Associa um evento de um manipulador de evento em tempo de execução.
AddHandler event, AddressOf eventhandler
Parts
event
O nome do evento para manipular.eventhandler
O nome de um procedimento que manipula o evento.
Comentários
O AddHandler e RemoveHandler instruções permitem iniciar e parar o evento tratamento a qualquer momento durante a execução do programa .
A assinatura do eventhandler procedimento deve corresponder à assinatura do evento event.
The Handles keyword and the AddHandler statement both allow you to specify that particular procedures handle particular events, but there are differences. The AddHandler statement connects procedures to events at run time. Use the Handles keyword when defining a procedure to specify that it handles a particular event. For more information, see Cláusula Handles (Visual Basic).
Observação |
---|
For custom events, the AddHandler statement invokes the event's AddHandler accessor. For more information on custom events, see Declaração de evento. |
Exemplo
Sub TestEvents()
Dim Obj As New Class1
' Associate an event handler with an event.
AddHandler Obj.Ev_Event, AddressOf EventHandler
' Call the method to raise the event.
Obj.CauseSomeEvent()
' Stop handling events.
RemoveHandler Obj.Ev_Event, AddressOf EventHandler
' This event will not be handled.
Obj.CauseSomeEvent()
End Sub
Sub EventHandler()
' Handle the event.
MsgBox("EventHandler caught event.")
End Sub
Public Class Class1
' Declare an event.
Public Event Ev_Event()
Sub CauseSomeEvent()
' Raise an event.
RaiseEvent Ev_Event()
End Sub
End Class
Consulte também
Referência
Cláusula Handles (Visual Basic)