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?

1
  • The Click event doesn't tell you which mouse button (if any) was clicked So handle the MouseClick event. stackoverflow.com/a/936615/284240 Commented Feb 27, 2013 at 15:40

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.