IMHO The intent is more to allow
handling the same event on multiple objects.
I agree, I don't think Microsoft intended the new event handling structure
to allow handling of different events from the same event handler. Instead
it is much more useful for catching the same event from different objects.
For example, consider the performance overhead. If you did have a single
event handler of all events and you did have a method of telling which event
is being handled then you would undoubtedly have to do some processing
(string or type or enum comparison) in order to determine the event. This
would add an additional overhead to handling each event as opposed to having
separate event handlers. Not good when handling performance critical events
such as Paint() etc. You would also end up with a method that is big and
contains code for doing completely separate things - not a good design.
IMHO, a method should have one clearly defined purpose and result.
In my opinion a good use of the new event handling structure is to catch the
same event from multiple objects. For example, say you have a form with 3
text boxes. You could write an event handler like the following to change
the back color of the active textbox to show it as highlighted:
----------------------------
Private Sub GotFocusHandler(sender as object, e as EventArgs) _
Handles Text1.GotFocus, _
Text2.GotFocus, _
Text3.GotFocus
ctype(sender, Control).BackColor = Color.Yellow
End Sub
Private Sub LostFocusHandler(sender as object, e as EventArgs) _
Handles Text1.LostFocus, _
Text2.LostFocus, _
Text3.LostFocus
Ctype(sender, Control).BackColor = SystemColors.Window
End Sub
----------------------------------------------
In the example above, you use the advantage of the new way of handling
events while keeping with good design (atomic methods) and without the
performance bottleneck of determining which event was fired.
Compare this to the way you (Christopher) would like it done:
---------------------------------------------
Private Sub FocusHandler(sender as object, e as EventArgs) _
Handles Text1.LostFocus, _
Text2.LostFocus, _
Text3.LostFocus, _
Text1.GotFocus, _
Text2.GotFocus, _
Text3.GotFocus
If e.Event is Text1.LostFocus or _
e.Event is Text2.LostFocus or _
e.Event is Text3.LostFocus then
Ctype(sender, Control).BackColor = SystemColors.Window
Else
ctype(sender, Control).BackColor = Color.Yellow
End If
End Sub
---------------------------------------------
Although you get away with a single function you have to deal with the
following disadvantages:
1) The performace overhead of determining the event with the IF statement
2) You have a function that is not atomic (it does more than one logical
thing)
3) Debugging may be a bit harder (suppose yor code causes another event to
happen - you have to debug the same function like a recursive call).
I hope this makes things clearer,
Best Regards,
Trev.