110,536
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication31
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
XEvent += new X(Form1_XEvent);
}
void Form1_XEvent()
{
throw new NotImplementedException();
}
public delegate void X();
X _X;
public event X XEvent
{
add
{
_X += value;
}
remove
{
_X -= value;
}
}
}
}
static void Main(string[] args)
{
System.Windows.Forms.Button btn = new System.Windows.Forms.Button();
btn.Click += new EventHandler(btn_Click);
btn.Click += new EventHandler(btn_Click2);
btn.Click += new EventHandler(btn_Click3);
PropertyInfo pi = btn.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
EventHandlerList ehl = (EventHandlerList)pi.GetValue(btn, null);
FieldInfo fieldInfo = (typeof(System.Windows.Forms.Control)).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic);
Delegate d = ehl[fieldInfo.GetValue(null)];
foreach (Delegate del in d.GetInvocationList())
Console.WriteLine(del.Method.Name);
}
static void btn_Click(object sender, EventArgs e)
{
Console.WriteLine("Click1");
}
static void btn_Click2(object sender, EventArgs e)
{
Console.WriteLine("Click2");
}
static void btn_Click3(object sender, EventArgs e)
{
Console.WriteLine("Click3");
}