日期:2014-05-18 浏览次数:21110 次
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"); }