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)   
            {   
                
    //什么也不干   
            }   
        }
    }
  • 相关阅读:
    Go的Web之旅【部署】
    module declares its path as: github.com/xxx/yyy【Go报错】
    android studio快捷键集合
    Web App 概述
    WIN10 kafka搭建完后命令测试步骤自用
    Echarts tab 切换解决图不能显示的问题
    如何为不定高度(height:auto)的元素添加CSS3 transition-property:height 动画
    手持设备开发项目实例
    SQL Server 查找表问题
    Tomcat 10 升级注意事项
  • 原文地址:https://www.cnblogs.com/kakaliush/p/1997499.html
Copyright © 2011-2022 走看看