Private Sub ClickButtons(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
'code here
End Sub
If sender is Button1 Then
MessageBox.show("Button1 was clicked")
End If
Private Sub btn1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btn1.MouseDown, btn2.MouseDown, btn3.MouseDown
Dim pintTemp As System.Object
pintTemp = sender
If e.Button = MouseButtons.Right Then
If pintTemp.ImageIndex = 2 Then
pintTemp.ImageIndex = 0
Else
pintTemp.ImageIndex += 1
End If
End If
'left click stuff here
End Sub
[CODE=visualbasic]
Private Sub ClickButtons(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
Dim ctlSender as Button = DirectCast(sender, Button)
Select Case ctlSender.Name
Case "Button1"
' code
Case "Button"
' code
End Select
End Sub
'P S E U D O C O D E
Private Sub AddHandlers()
Dim btnType As Type = GetType(System.Windows.Forms.Button)
Dim aCtl as Control
For each aCtl in me.Contols
If btnType.IsInstanceOfType(aCtl) Then
AddHandler aCtl.ButtonClick, AddressOf me.ButtonClick
end if
Next aCtl
End sub
Private Sub ButtonClick (Sender as Object, e as System.EventArgs)
'Here you can possibly determine the x/y coordinates of the mousepointer! This will probably make your code much more straightforward
DoStuff
End sub