如何从事件中删除所有处理程序?

时间:2013-01-17 15:23:29

标签: vb.net crystal-reports-2010

Private Sub SetupToolStrip(ByVal ControlCollection As Control.ControlCollection)
        For Each aControl As Control In ControlCollection
            If TypeOf aControl Is System.Windows.Forms.ToolStrip Then
                Dim ToolBar As System.Windows.Forms.ToolStrip = DirectCast(aControl, System.Windows.Forms.ToolStrip)
                For Each Item As System.Windows.Forms.ToolStripItem In ToolBar.Items
                    If Item.ToolTipText = "Print Report" Then
                           AddHandler Item.Click, AddressOf VerificDacaPrintam
                    End If
                Next
           End If
          If Not aControl.Controls Is Nothing Then SetupToolStrip(aControl.Controls)
       Next
 End Sub

但我想在删除之前删除Item.Click的所有事件:

AddHandler Item.Click, AddressOf VerificDacaPrintam

以下不起作用:

Item.Click = Nothing       

Dim del As [Delegate]() = Item.Click.GetInvocationList() 

它说“Click是一个事件,不能直接调用。使用'RaiseEvent'语句来引发一个事件。”

1 个答案:

答案 0 :(得分:-1)

你可以用这个:

RemoveHandler Obj.Ev_Event, AddressOf EventHandler

MSDN Documentation