using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; namespace WinTest.Event { public partial class frmEvent : Form { public frmEvent() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.MyEvent += new EventHandler(p_MyEvent); this.MyEvent += new EventHandler(p_MyEvent2); this.MyEvent += new EventHandler(p_MyEvent3); EventHandler eh = this.MyEvent; foreach (Delegate del in eh.GetInvocationList()) { Console.WriteLine(del.Method.Name); } System.Windows.Forms.Button btn = new System.Windows.Forms.Button(); btn.Click += new EventHandler(btn_Click); btn.Click += new EventHandler(btn_Click); btn.Click += new EventHandler(btn_Click); PropertyInfo pi = btn.GetType().GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic); EventHandlerList
.Net C# - 如何获得一个事件(Event)的订阅者(Handler)的数量和列表?(例程)
最新推荐文章于 2023-07-23 01:49:37 发布
本文档展示了如何在C#中检查并获取一个事件(Event)的订阅者数量以及订阅者列表。通过实例代码,分别演示了对自定义事件、WinForm Button控件的Click事件和BackgroundWorker组件的DoWork事件的处理方法列表的获取方法。
摘要由CSDN通过智能技术生成