MouseButtons always returns as None

N

Nancy

My understanding is that MouseButtons should return which mouse button has
been pressed. This method exists in the Control class. However, None is
always returned as the value when left or right button pressed, and I don't
know why. I get the same results using any of the following syntax:
MouseButtons, Me.MouseButtons, Panel1.MouseButtons. I'm clicking on a panel
located on a form. Is this a bug?

Private Sub Panel1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Panel1.Click
Select Case MouseButtons
Case MouseButtons.Left
Debug.WriteLine("Left mouse button pressed.")
Case MouseButtons.Right
Debug.WriteLine("Right mouse button pressed.")
Case MouseButtons.None
Debug.WriteLine("None mouse button detected.") '<-- always get
this response
Case Else
Debug.WriteLine("It doesn't know which mouse button was
pressed.")
End Select
End Sub
 
A

Andrew S \(Infragistics\)

Its not really a bug. The Click event is invoked AFTER the mouse button has
been released so the Control.MouseButtons would return none at that point.
If you need this information, you'll need to catch the mousedown and store
which mouse button was clicked.
 
N

Nancy

Thanks Andrew, that helped!
Nancy

Andrew S (Infragistics) said:
Its not really a bug. The Click event is invoked AFTER the mouse button has
been released so the Control.MouseButtons would return none at that point.
If you need this information, you'll need to catch the mousedown and store
which mouse button was clicked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top