コントロールイベントのすべての依頼を取得(C#)

1639 ワード

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);
}