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

通过反射来获取某个窗体注册过的事件
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)   
        {   
            
//什么也不干   
        }   
    }
}
原文地址:https://www.cnblogs.com/kakaliush/p/1997499.html