|
-
Jan 6th, 2008, 06:20 AM
#1
Thread Starter
Member
[RESOLVED] Make a button right or left click sensitive
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
-
Jan 6th, 2008, 07:57 AM
#2
Re: Make a button right or left click sensitive
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
-
Jan 6th, 2008, 08:05 AM
#3
Re: Make a button right or left click sensitive
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
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.

-
Jan 6th, 2008, 08:14 AM
#4
Thread Starter
Member
Re: Make a button right or left click sensitive
oh dude you're a genius!!
thank you so much!!
-
Jan 6th, 2008, 08:28 AM
#5
Re: Make a button right or left click sensitive
 Originally Posted by some1uk03
It is actually possible..
Simply use the Mouse_Down event
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.
-
Jan 6th, 2008, 09:09 AM
#6
Thread Starter
Member
Re: [RESOLVED] Make a button right or left click sensitive
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.
-
Jan 6th, 2008, 09:18 AM
#7
Re: [RESOLVED] Make a button right or left click sensitive
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.
-
Jan 6th, 2008, 09:50 AM
#8
Re: [RESOLVED] Make a button right or left click sensitive
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
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|