得到控件事件中的全部委托(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);
}

 

你可能感兴趣的:(C#)