积极答复者
C# 如何撤销事件绑定的匿名委托?

问题
答案
-
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); } }
- 已标记为答案 leeTobill 2010年10月29日 9:40
全部回复
-
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); } }
- 已标记为答案 leeTobill 2010年10月29日 9:40