Create an Eventhandler via class

Create an Eventhandler via class

I have an application with lots of ListBox controls. I was wondering if it would be possible to add the eventhandler for the onselectedindexchanged in the constructor of the Listbox? All listboxes will use the same method for this.

I know I can add them manually but I was hoping for a solution that would change all the ones I currently have to use the same eventhandler and when I add a new one to not have to tie to the method.

Questions about OO in PHP continued


class method inheritance question
You could simply iterate over the controls? For example (in your Form's / Control's ctor, after initiaize):.
How to get properties Names from object parameter?
CascadeListBoxEvent(this, MyHandlerMethod) 
using the utility method:.
Access an instance from Terminal
static void CascadeListBoxEvent(Control parent, EventHandler handler) {     Queue<Control> queue = new Queue<Control>();     queue.Enqueue(parent);     while (queue.Count > 0)     {         Control c = queue.Dequeue();         ListBox lb = c as ListBox;         if (lb != null)         {             lb.SelectedIndexChanged += handler;         }         foreach (Control child in c.Controls)         {             queue.Enqueue(child);         }     } } 

Where is the Python documentation for the special methods? (__init__, __new__, __len__, …)

85 out of 100 based on 55 user ratings 205 reviews