H
Herfried K. Wagner [MVP]
I have added few of the events in some control, example code is:
btnControl.GotFocus +=new EventHandler(EventHandlingMethod);
btnControl.Click +=new EventHandler(EventHandlingMethod);
lblControl.Click +=new EventHandler(EventHandlingMethod);
private void EventHandlingMethod(object sender, EventArgs e)
{
.......
}
btnControl = Button object, lblControl = Lable object
Now the problem is: I am adding the same event handler method in all events
for btnControl and lblControl too.
now in EventHandlingMethod method, i can find which control is using sender
but now if i want to put some switch cases in the method for Event Name then
I have no any such information in the eventargs or anyother way....
=======
I am curious which sense handling different events of different controls in
the same event handler would make. Instead, add separate event handlers for
all event types, not just delegate types. This means separate handlers for
controls' 'Click' and 'GotFocus' events.
btnControl.GotFocus +=new EventHandler(EventHandlingMethod);
btnControl.Click +=new EventHandler(EventHandlingMethod);
lblControl.Click +=new EventHandler(EventHandlingMethod);
private void EventHandlingMethod(object sender, EventArgs e)
{
.......
}
btnControl = Button object, lblControl = Lable object
Now the problem is: I am adding the same event handler method in all events
for btnControl and lblControl too.
now in EventHandlingMethod method, i can find which control is using sender
but now if i want to put some switch cases in the method for Event Name then
I have no any such information in the eventargs or anyother way....
=======
I am curious which sense handling different events of different controls in
the same event handler would make. Instead, add separate event handlers for
all event types, not just delegate types. This means separate handlers for
controls' 'Click' and 'GotFocus' events.