2013-01-17 89 views
1
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'語句來引發事件。「

+0

可能重複://計算器.com/questions/293007/is-it-it-it-it-it-to-steal-an-event-handler-from-one-control-and-give-it-to-anoth) –

回答

-1

您可以使用此:

RemoveHandler Obj.Ev_Event, AddressOf EventHandler 

MSDN Documentation

的[是否有可能從一個控制「偷」的事件處理程序,並把它給別人呢?(HTTP
+0

但我不知道EventHandler的名字。當我嘗試使用「Dim del As [Delegate]()= Item.Click.GetInvocationList()」獲取所有eventhadlers的列表時,它說「Click是一個事件,不能直接調用。使用'RaiseEvent'聲明提出事件。「 – user1987580

+0

任何我需要處理CrystalReportViewer打印按鈕上的單擊事件的EventHandler。你知道這件事嗎? – user1987580

+0

http://stackoverflow.com/questions/1150250/removing-all-event-handlers-in-one-go – SysDragon

相關問題