0

In a C# Application we can add an Event Handler like this.button3.Click += new System.EventHandler(this.button3_Click); also we can Remove this.button3.Click -= new System.EventHandler(this.button3_Click); so it means we can add as much as we want event's in an UI Control ,so my question is how can i Explore or Iterate and Remove a Specific Event from an UI . Eg . If we can in someway populate all Events of an Control on a ListBox (if it's possible) and remove the Selected One .

PS : Im kinda a Junior Programmer ,so i think Code Reflection handles this portion. Bests

Rosmarine Popcorn
  • 10,761
  • 11
  • 59
  • 89
  • Possible duplicate http://stackoverflow.com/questions/5989889/store-a-list-of-eventhandlers-to-unsubscribe-from – oleksii May 30 '11 at 13:39

1 Answers1

1

You can easily display a list of all possible events for your component with a code like

EventInfo[] allEvents = Button1.GetType().GetEvents(System.Reflection.BindingFlags.Instance
    | System.Reflection.BindingFlags.Public);
foreach (EventInfo curEvent in allEvents)
{
    EventsListBox.Items.Add(curEvent.Name);
}

However, it seems impossible to know which methods are assigned to the delegates, that will be called in case of an event, outside of the component. You can refer to How do I find out if a particular delegate has already been assigned to an event?, Determine list of event handlers bound to event and Iterating through event handlers

Community
  • 1
  • 1
LoBo
  • 212
  • 1
  • 2
  • 9