如何在VB.NET中删除事件处理程序

时间:2012-06-20 18:31:26

标签: vb.net winforms handler

  

可能重复:
  VB.NET RemoveHandler & Anonymous Methods

如果我添加这样的事件处理程序:

AddHandler s.Click, AddressOf Panel1_Click

我怎样才能删除事件处理程序?

Private Sub Panel1_click(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Remove code
End Sub

2 个答案:

答案 0 :(得分:16)

您可以使用RemoveHandler运算符执行此操作:

Private Sub Panel1_click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim panel As Panel = CType(sender, Panel)
    RemoveHandler panel.Click, AddressOf Panel1_Click
End Sub

答案 1 :(得分:5)

与添加它的方式相同:

RemoveHandler s.Click, AddressOf Panel1_Click

http://msdn.microsoft.com/en-us/library/3xz97kac.aspx