高手进!!!事件委托多个函数,如果知道事件委托了多少个函数?

zetee 2009-02-11 04:35:58
事件委托多个函数,
this.button1.Click += new System.EventHandler(this.button1_Click1);

this.button1.Click += new System.EventHandler(this.button1_Click2);

如果知道事件委托了多少个函数?


...全文
84 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dobzhansky 2009-02-11
  • 打赏
  • 举报
回复
对, 是

GetInvocationList
CsToD 2009-02-11
  • 打赏
  • 举报
回复

Type t = button1.GetType();
PropertyInfo pi = t.GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
EventHandlerList ehl = (EventHandlerList)pi.GetValue(button1, null);
FieldInfo fieldInfo = (typeof(Control)).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic);
Delegate d = ehl[fieldInfo.GetValue(null)];
if (d != null)
{
foreach (Delegate temp in d.GetInvocationList())
{
MessageBox.Show(temp.Method.Name);
}
}
zetee 2009-02-11
  • 打赏
  • 举报
回复
郁闷。人呢

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧