1

Similar to: Get the ID/Name of a button in a click event. VB.NET ?

I am looking to find whether the left or right button was clicked on a mouse. I have declared a block class which holds buttons. I've assigned an event to the button click through:

Class Block
  Public X As Integer
  Public Y As Integer
  Public type As String
  Public status As String
  Public text As String
  Public WithEvents button As Button

  Private Sub btnReveal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button.Click
  ....
  ....
  End Sub

This works fine, but when I try to pick up the right button click using:

    If e.Button = MouseButtons.Right Then
        MessageBox.Show("RH click")
    Else
        button.Text = text
        button.BackColor = Color.LightGray
    End If

It complains on e.Button: Button is not a member of System.EventArgs

Any ideas?

Community
  • 1
  • 1
pluke
  • 3,832
  • 5
  • 45
  • 68
  • The `Click` event doesn't tell you which mouse button (if any) was clicked So handle the `MouseClick` event. http://stackoverflow.com/a/936615/284240 – Tim Schmelter Feb 27 '13 at 15:40

1 Answers1

4

Handle the MouseUp or MouseDown Events. They pass the MouseEventArgs.

Abdusalam Ben Haj
  • 5,343
  • 5
  • 31
  • 45
  • So I was just testing to make sure before writing a very similar answer and I find that when I'm handling MouseClick it knows if it's the left button, but not if it's the right. And if I'm handling the mouseUp event, it knows either way. – clweeks Feb 27 '13 at 15:44