该篇文章是我于2009年6月10日通过自己编写的工具,批量从位于在博客园的博客站点(http://chenxizhang.cnblogs.com)同步而来。文章中的图片地址仍然是链接到博客园的。特此说明! 陈希章原文地址:http://www.cnblogs.com/chenxizhang/archive/2009/06/06/1497392.html原文标题:如何取得某个菜单所绑定的所有事件处理程序 原文发表:2009/6/5 23:23:00 |
ToolStripItem item = sender as ToolStripItem;
PropertyInfo propertyInfo = (typeof(ToolStripItem)).GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
EventHandlerList eventHandlerList = (EventHandlerList)propertyInfo.GetValue(item, null);
FieldInfo fieldInfo = (typeof(ToolStripItem)).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic);
Delegate d = eventHandlerList[fieldInfo.GetValue(null)];
if (d != null)
{
foreach (Delegate temp in d.GetInvocationList())
{
//这里已经取得了所有Click事件绑定的处理程序,可以做一些事情。例如下面的代码是撤销所有的事件注册
item.Click -= temp as EventHandler;
}
}
作者:陈希章 出处:http://blog.youkuaiyun.com/chen_xizhang 本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |