Im trying to get all registered events of a standard control (in this example: a Button), aka all events that have self defined code behind it. So basically the same list you would see in the designer, without the "empty" events. In my case I want the events of a simple Button. The button has an "on-click" event and none other.
I tried countless methods i found on this site and scattered around the web but none of them seem to work for me. Most recently i tried this:
foreach (var e in typeof(Button).GetEvents()) //typeof(Button) just to make sure there is no error here
{
FieldInfo fi = c.GetType().GetField(e.Name, BindingFlags.Public | BindingFlags.NonPublic |
BindingFlags.Static | BindingFlags.Instance |
BindingFlags.DeclaredOnly);
if (fi != null)
{
object value = fi.GetValue(c);
if (value == null)
{
message += e.Name;
}
}
}
Given "c" is a normal Button with an "on_Click" event, "message" is a string.
Am I over-looking something? Is it not possible to get all registered events of a Control anyway? What am I doing wrong? Id greatly appreciate some help/pointers.