Nota
O acesso a esta página requer autorização. Pode tentar iniciar sessão ou alterar os diretórios.
O acesso a esta página requer autorização. Pode tentar alterar os diretórios.
Remove a associação entre um evento e um manipulador de eventos.
Sintaxe
RemoveHandler event, AddressOf eventhandler
Partes
| Período | Definição |
|---|---|
event |
O nome do evento que está sendo manipulado. |
eventhandler |
O nome do procedimento que atualmente manipula o evento. |
Observações
As AddHandler instruções and RemoveHandler permitem iniciar e parar a manipulação de eventos para um evento específico a qualquer momento durante a execução do programa.
Observação
Para eventos personalizados, a RemoveHandler instrução invoca o acessador do RemoveHandler evento. Para obter mais informações sobre eventos personalizados, consulte Declaração de evento.
Exemplo
Public Class DataBindingExample
Private textBox1 As TextBox
Private ds As DataSet
Public Sub New()
textBox1 = New TextBox()
ds = New DataSet()
SetupSampleData()
BindControlWithAddHandler()
End Sub
Private Sub SetupSampleData()
Dim table As New DataTable("Orders")
table.Columns.Add("OrderAmount", GetType(Decimal))
table.Rows.Add(123.45D)
table.Rows.Add(67.89D)
ds.Tables.Add(table)
End Sub
Private Sub BindControlWithAddHandler()
Dim binding As New Binding("Text", ds, "Orders.OrderAmount")
' Use AddHandler to associate ConvertEventHandler delegates
AddHandler binding.Format, AddressOf DecimalToCurrency
AddHandler binding.Parse, AddressOf CurrencyToDecimal
textBox1.DataBindings.Add(binding)
End Sub
Private Sub DecimalToCurrency(ByVal sender As Object, ByVal e As ConvertEventArgs)
If e.DesiredType IsNot GetType(String) Then
Return
End If
e.Value = CDec(e.Value).ToString("c")
End Sub
Private Sub CurrencyToDecimal(ByVal sender As Object, ByVal e As ConvertEventArgs)
If e.DesiredType IsNot GetType(Decimal) Then
Return
End If
e.Value = Convert.ToDecimal(e.Value.ToString())
End Sub
End Class
' Simple example for basic AddHandler usage
Sub TestBasicEvents()
Dim Obj As New Class1
AddHandler Obj.Ev_Event, AddressOf EventHandler
Obj.CauseSomeEvent()
RemoveHandler Obj.Ev_Event, AddressOf EventHandler
Obj.CauseSomeEvent()
' Lambda expression example
AddHandler Obj.Ev_Event, Sub ()
MsgBox("Lambda caught event.")
End Sub
Obj.CauseSomeEvent()
End Sub
Sub EventHandler()
MsgBox("EventHandler caught event.")
End Sub
Public Class Class1
Public Event Ev_Event()
Sub CauseSomeEvent()
RaiseEvent Ev_Event()
End Sub
End Class