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

相关文章:

  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2021-05-28
  • 2021-10-12
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
猜你喜欢
  • 2021-11-07
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
相关资源
相似解决方案