The DirectCast statement simply converts the "sender" variable (which is
declared as an Object) to a Button. Essentially, if you click on Button1
you
get Button1 passed to the Click event handler as an object. Cast it back
to
a Button and you can do anything you want with it including accessing
it's
properties such as name, text, position, etc....
See this discussion for some more information. It's a very similar
problem... at least the part about adding multiple buttons...
http://www.devcity.net/forums/topic.asp?tid=4087&page=2
Remember in VB.NET you can have a single event handler handle multiple
events (as above) and you can have a single event handled by multiple
handlers...
Private Sub Stuff1(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles Button1.Click
End Sub
Private Sub Stuff2(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MenuItem2.Click
End Sub
Private Sub Stuff3(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MenuItem2.Click ,
Button1.Click
End Sub
In the above if you click Button1: Stuff1 & Stuff3 will execute, if you
click MenuItem2: Stuff2 & Stuff3 will execute.
In addition to the Handles keyword, you can use AddHandler &
RemoveHandler
to handle an event.
"mark" <ma**@discussio ns.microsoft.co m> wrote in message
news:D8******** *************** ***********@mic rosoft.com:
Is there a means of raising an event when ANY button on a windows
application
form is clicked wherein the actual button clicked can be determined in the
generic click events code (eg by way of interogating the sender)?