您的位置:首页 > 其它

委托事件的另类取消方法

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);
}
}

这个方法适合在不知道委托事件的详细情况下,取消所有的委托事件。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: