• 通过反射来获取窗体注册过的事件


    通过反射来获取某个窗体注册过的事件
    namespace WindowsFormsApplication1
    {
        
    public partial class Form1 : Form
        {
            
    public Form1()   
            {   
                InitializeComponent();   
      
                
    this.Load += new EventHandler(Form1_Load1);   
                
    this.Load += new EventHandler(Form1_Load2);   
      
                PropertyInfo propertyInfo 
    = (typeof(Form)).GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);   
                EventHandlerList eventHandlerList 
    = (EventHandlerList)propertyInfo.GetValue(thisnull);   
                FieldInfo fieldInfo 
    = (typeof(Form)).GetField("EVENT_LOAD", BindingFlags.Static | BindingFlags.NonPublic);   
      
                Delegate d 
    = eventHandlerList[fieldInfo.GetValue(null)];   
      
                
    if (d != null)   
                {   
                    
    foreach (Delegate de in d.GetInvocationList())   
                        MessageBox.Show(de.Method.Name);   
                }   
            }   
            
    private void Form1_Load1(object sender, EventArgs e)   
            {   
                
    //什么也不干   
            }   
            
    private void Form1_Load2(object sender, EventArgs e)   
            {   
                
    //什么也不干   
            }   
        }
    }
  • 相关阅读:
    C#综合揭秘——Entity Framework 并发处理详解
    Apache2.2+Tomcat7.0整合配置详解
    python操作excel
    NameError: name ‘time‘ is not defined
    ping命令最实用的
    github使用方法
    数字证书
    网络编程
    不辣的皮特
    msdn上的“索引器”(indexer)示例
  • 原文地址:https://www.cnblogs.com/kakaliush/p/1997499.html
Copyright © 2020-2023  润新知