zoukankan      html  css  js  c++  java
  • 利用反射查找绑定事件

    1.手动创建一个控件

    2.反射查找事件,绑定事件到控件 

     1 private EventHandler BindEvent(ToolStripMenuItem Toostrip,string EventName)
     2 {
     3     PropertyInfo propertyInfo = (typeof(ToolStripMenuItem)).GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreReturn | BindingFlags.IgnoreCase);
     4             
     5     EventHandlerList eventHandlerList = (EventHandlerList)propertyInfo.GetValue(Toostrip, null);
     6 
     7     FieldInfo fieldInfo = (typeof(ToolStripMenuItem)).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
     8          
     9     Delegate d = eventHandlerList[fieldInfo.GetValue(null)];
    10     if (d != null)
    11     {
    12         foreach (Delegate de in d.GetInvocationList())
    13         { 
    14                     
    15             //textBox1.Text += de.Method.Name;
    16             if (d.Method.Name == EventName)
    17             {
    18                 return (EventHandler)d;
    19             }
    20         }
    21     }
    22     return null;
    23 }
  • 相关阅读:
    Prometheus监控k8s集合
    docker集合
    开源堡垒机jumpserver
    ELK日志分析平台
    安全名称解释
    CPU上下文切换
    平均负载
    234. 回文链表
    125. 验证回文串
    122. 买卖股票的最佳时机II
  • 原文地址:https://www.cnblogs.com/kingkongv/p/2635629.html
Copyright © 2011-2022 走看看