VB.NET buttons

  • Thread starter Thread starter KAB
  • Start date Start date
K

KAB

Hi All:
I've just noticed that buttons in VB.net only allows a left click with the
mouse. Is there a way the button can be clicked with the right click of the
mouse? The program would be able to respond to which mouse button was
clicked for example:

If the left mouse button was clicked while the cursor is on a specific
VB.net button then: msgbox("The left mouse button was clicked")

If the right mouse button was clicked while the cursor is on the same VB.net
button then: msgbox("The right mouse button was clicked")

Thanks
KAB
 
Take a look at the mouse down event on the button.

Private Sub Button1_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Right Then
MessageBox.Show("right clicked mousedown")
End If
End Sub
 
KAB,

Be aware that the right click holds often the context menu which is standard
in some controls.

Cor
 
Miro said:
Take a look at the mouse down event on the button.

Private Sub Button1_MouseDown(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles Button1.MouseDown
If e.Button = Windows.Forms.MouseButtons.Right Then
MessageBox.Show("right clicked mousedown")
End If
End Sub


Thanks Miro it looks like this solved the problem. You are a great help KAB
 
Cor Ligthert said:
KAB,

Be aware that the right click holds often the context menu which is standard
in some controls.

Cor



Although this isn't the cause of my programming problem, it is a good tip to keep in mind with other controls.
Thanks
KAB
 
Patrice said:
Try the MouseClick event that gives details (Click also works when the
button is "clicked" without the mouse). In all cases double check that the
UI won't be too confusing if this is directed to end -users...

--
Patrice


Thanks, the code provided by Miro has solved the problem (at least for now). I will check into the MouseClick event as you suggest. It will give me another approach for a solution. One thing that is clear to me, I have a lot to learn before I'll understand this VB.NET.
Thanks Again
KAB
 
Be aware that this is not VB Net, it is simpley that VB is now extended with
Net. This behaviour is a standard part of Net not of VB.

Cor
 
Or mouseup because mouse down is not really a click, that is as well for
mouseup, but the change that an up was a click is much higher

Cor
 
Back
Top