hi everyone
as my title says i need to know for example how to make button only work when it is right clicked, and another button only when it is left clicked. is this possible??
help greatly appreciated :)
thanks
Printable View
hi everyone
as my title says i need to know for example how to make button only work when it is right clicked, and another button only when it is left clicked. is this possible??
help greatly appreciated :)
thanks
Command buttons only work on left click anyway
You could use something like the following to qualify a right click (returns true if the mouse is over the control) BUT the button will still only move up and down on Left clicks. The only way I can think of to make a button visually respond to right clicks would be to subclass the window and capture the mouse click before the window gets it, not shown here.
Code:Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If InRangeClick(Button, X, Y, Command1.Width, Command1.Height, vbRightButton) Then
Debug.Print "Right click!"
End If
End Sub
Private Function InRangeClick(Button As Integer, ByVal X As Single, ByVal Y As Single, pWidth As Single, pHeight As Single, Optional ButtonPref As Integer = &HFFFF) As Boolean
'generic function to cover all controls
If Button And ButtonPref Then
Select Case X
Case Is < 0
Case Is <= pWidth
Select Case Y
Case Is < 0
Case Is <= pHeight: InRangeClick = True
End Select
End Select
End If
End Function
It is actually possible..
Simply use the Mouse_Down event
Code:Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then MsgBox "Right Click"
If Button = 1 Then MsgBox "Left Click"
End Sub
oh dude you're a genius!!
thank you so much!! :D :D
I was trying to simulate a mouse click which occurs as you release the mouse, immediately before mouse up and then only if the mouse is over the control. The code I show does this but the command button only visually shows a click if you use the left button, which is my point about sub-classing.Quote:
Originally Posted by some1uk03
i needed this for a label, i had to click on it and change into 2 different colors. using Mouse_Down event it may not show it visually...but i dont think it ever does with labels does it?
if i have to do the same thing again in future but with a button, i will probably use your method as it looks better when it shows it with both left and right click.
:rolleyes: My method does not show the button going up and down on right click. For that you need to subclass.
Am I repeating myself?
Anyhow for what you want Someluke03 is your man.
Just keep in mind that as far as VB is concerned the command button has not been clicked when using the MouseDown event. In other words if you write the code below anywhere in your app (including the MouseDown event) it will return False. So if you need to check the Command1.Value elsewhere in your app (which happens often) then you will have to write a work around.
Code:Print Command1.Value