Keith said:
Is there a way to attach event handler code to multiple controls?
Say, you have a common event handler, which you want to fire for different controls, say all buttons
should fire it among with their own events. You do this:
void MyCommonHandler(object sender, EventHandler e)
{
... do whatever ..
... usually check who is the sender ...
... like this ...
if (sender is btnFirst)
{
... do something useful ...
}
else if ( ... ) { ... }
}
Now, somewhere, say in form constructor, you say:
btnFirst.Click += new EventHandler(MyCommonHandler);
btnSecond.Click += new EventHandler(MyCommonHandler);
.... etc...
Note, that the Button.Click can have more than one event attached to it, so for example you can also
add specific event handlers to those buttons along with the common one.
Hope it helps,
Andrey