VB.NET buttons

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
 
M

Miro

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
 
C

Cor Ligthert[MVP]

KAB,

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

Cor
 
K

KAB

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
 
K

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
 
K

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
 
C

Cor Ligthert[MVP]

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
 
C

Cor Ligthert[MVP]

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
 

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