It is possible to know what button is clicked, but in many cases, this is wrong approach. In most cases, you just handle each button with its separate handle. The problem is simple: where you really reuse then code, and where you just Repeat Yourself (one of the most important rules: don't repeat yourself, http://en.wikipedia.org/wiki/Don%27t_repeat_yourself
]). Well, let's compare:
Dim buttonFirst As System.Windows.Forms.Button = Dim buttonSecond As System.Windows.Forms.Button =
AddHandler buttonFirst.Click, Address of HandleButtonClick
AddHandler buttonSecond.Click, Address of HandleButtonClick
Private Sub HandleButtonClick(sender As Object, eventArgs As System.EventArgs)
Dim buffon As System.Windows.Forms.Button = DirectCast(sender, System.Windows.Forms.Button)
If button = buttonFirst Then Else
In the sample above, you reused one method between two handlers, but did you reused the code? No, you just pushed ugliness into "if" statement.
So, how about individual handlers then? Let's see:
AddHandler buttonFirst.Click, Sub(sender As Object, eventArgs As System.EventArgs) End Sub
AddHandler buttonSecond.Click, Sub(sender As Object, eventArgs As System.EventArgs)
Isn't it better? It depends on what you want to write instead of the code depicted with "...".
. You can use the same method for several several events of different controls, but it pays off only if these handlers should do something really similar, besides, it requires type case and actually using first parameter. If it's just two button (or something else) instances doing something different, it's much better to use individual methods for handling the event on each.