得到控件事件中的全部委托(C#)

Type btn = typeof(Button);
Type ctrl = typeof(Control);
PropertyInfo proInfo = btn.GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance);
EventHandlerList eventList = (EventHandlerList)proInfo.GetValue(button1, null);
//eventList[Control.EventClick]
FieldInfo fieldInfo = ctrl.GetField("EventClick", BindingFlags.NonPublic | BindingFlags.Static);
object key = fieldInfo.GetValue(null);
Delegate del = eventList[key];
Delegate[] delList = del.GetInvocationList();

foreach (Delegate item in delList)
{
    this.listBox1.Items.Add(item.Method.Name);
}

 

posted @ 2011-05-07 16:20  CoderWayne  阅读(345)  评论(0编辑  收藏  举报