zoukankan      html  css  js  c++  java
  • 通过反射来获取窗体注册过的事件

    通过反射来获取某个窗体注册过的事件
    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)   
            {   
                
    //什么也不干   
            }   
        }
    }
  • 相关阅读:
    Oracle适配问题解决
    Oracle12C创建视图权限不足
    Oracle12C配置对外访问
    Oracle12C创建scott账户
    Oracle12C安装配置文档
    Redis适配采坑记
    Redis安装问题解决方案
    Redis Linux 安装部署
    【计网 第四章-2】
    【信息论编码2】测度论
  • 原文地址:https://www.cnblogs.com/kakaliush/p/1997499.html
Copyright © 2011-2022 走看看