积极答复者
如何删除事件处理程序

问题
答案
-
试试这段代码:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click RemoveClickEvent(Me.Button1) End Sub Private Sub RemoveClickEvent(b As Button) Dim f1 As FieldInfo = GetType(Control).GetField("EventClick", BindingFlags.[Static] Or BindingFlags.NonPublic) Dim obj As Object = f1.GetValue(b) Dim pi As PropertyInfo = b.[GetType]().GetProperty("Events", BindingFlags.NonPublic Or BindingFlags.Instance) Dim list As EventHandlerList = DirectCast(pi.GetValue(b, Nothing), EventHandlerList) list.[RemoveHandler](obj, list(obj)) End Sub
注意importImports System.Reflection Imports System.ComponentModel
希望有用。
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike FengModerator 2011年12月15日 10:14
全部回复
-
试试这段代码:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click RemoveClickEvent(Me.Button1) End Sub Private Sub RemoveClickEvent(b As Button) Dim f1 As FieldInfo = GetType(Control).GetField("EventClick", BindingFlags.[Static] Or BindingFlags.NonPublic) Dim obj As Object = f1.GetValue(b) Dim pi As PropertyInfo = b.[GetType]().GetProperty("Events", BindingFlags.NonPublic Or BindingFlags.Instance) Dim list As EventHandlerList = DirectCast(pi.GetValue(b, Nothing), EventHandlerList) list.[RemoveHandler](obj, list(obj)) End Sub
注意importImports System.Reflection Imports System.ComponentModel
希望有用。
Mike Feng
MSDN Community Support | Feedback to us
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Mike FengModerator 2011年12月15日 10:14