委托事件的另类取消方法
2009-10-09 10:55
288 查看
/article/6157598.html
Type t = button1.GetType();
PropertyInfo pi = t.GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
EventHandlerList ehl = (EventHandlerList)pi.GetValue(button1, null);
FieldInfo fieldInfo = (typeof(Control)).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic);
Delegate d = ehl[fieldInfo.GetValue(null)];
if (d != null)
{
foreach (Delegate temp in d.GetInvocationList())
{
ehl.RemoveHandler(fieldInfo.GetValue(null), temp);
}
}
这个方法适合在不知道委托事件的详细情况下,取消所有的委托事件。
Type t = button1.GetType();
PropertyInfo pi = t.GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
EventHandlerList ehl = (EventHandlerList)pi.GetValue(button1, null);
FieldInfo fieldInfo = (typeof(Control)).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic);
Delegate d = ehl[fieldInfo.GetValue(null)];
if (d != null)
{
foreach (Delegate temp in d.GetInvocationList())
{
ehl.RemoveHandler(fieldInfo.GetValue(null), temp);
}
}
这个方法适合在不知道委托事件的详细情况下,取消所有的委托事件。
相关文章推荐
- C# 委托事件的另类取消方法
- 取消事件所有委托方法
- Javascript公共脚本库系列(二): 添加事件多播委托的方法
- JQuery事件e参数的方法preventDefault()取消默认行为
- 温故而知新:Delegate,Action,Func,匿名方法,匿名委托,事件
- 对jQuery中on方法委托事件的理解
- 委托、事件、匿名方法、Lambda
- 委托、匿名方法、事件学习小结
- C#解惑2——Delegate,Action,Func,匿名方法,匿名委托,事件(转)
- 关于C#.Net中事件(event)、委托(delegate)和方法的一点理解
- Delegate,Action,Func,匿名方法,匿名委托,事件
- 初步理解委托、事件、匿名方法和Lambda
- 使用 jquery 事件委托的 on 方法
- jquery取消事件冒泡的三种方法
- 清除事件所有委托方法
- C#中的委托和事件(2) ---将方法绑定到委托
- 温故而知新:Delegate,Action,Func,匿名方法,匿名委托,事件
- Delegate,Action,Func,匿名方法,匿名委托,事件
- js动态添加onload、onresize、onscroll事件(另类方法)
- jquery事件委托的回调函数中调用全局变量的简单方法