MouseButtons always returns as None

  • Thread starter Thread starter Nancy
  • Start date Start date
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
 
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.
 
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.
 
Back
Top