Userform - Option Button Events

mortgageman

Well-known Member
Joined
Jun 30, 2005
Messages
2,015
In the list that VBA gives you for the possible Option Button Events, I do not see Right Click. (I see click and doubleclick). Is there any way to distinguish between a left and right click (for an Option Button Event)?

Gene, "The Mortgage Man", Klein
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
mortgageman,

As far as I know, there is no such event for Option Buttons athough some API code could probably achieve a close solution.

What do you want to see when you right click the Option Button anyway ?

Regards.
 
Upvote 0
I have programmed The Game of Wari (aka Mandinka) in Excel. In General terms, the user has 6 choices each time s/he moves. I currently use 6 option buttons for this. I thought it would be pretty cool if by clicking on the right button, the user would see the effect of his move without it actually taking effect (I would use a MultiPage control for this I guess).

BTW - Since I could never have done any of this without the help from people on this board, I would be happy to upload the game as it is now if anyone wants it (and I knew how to upload files - which of course I don't)

Gene, "The Mortgage Man", Klein
 
Upvote 0
**bump**

So is there no way (other than to have two option buttons for each choice) to handle this feature?

Gene, "The Mortgage Man", Klein
 
Upvote 0
Private Sub OptionButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
MsgBox "Your left click code goes here", , "Left button"
ElseIf Button = 2 Then
MsgBox "Your right click code goes here", , "Right button"
End If
End Sub
 
Upvote 0
Tom (or anyone) quick question: Why are there arguments (Shift, X and Y) that are not used?

Gene, "The Mortgage Man", Klein


Private Sub OptionButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Button = 1 Then
MsgBox "Your left click code goes here", , "Left button"
ElseIf Button = 2 Then
MsgBox "Your right click code goes here", , "Right button"
End If
End Sub
_________________
Tom Urtis
 
Upvote 0
I don't know what you mean by "that are not used". The only reason those parameters would not be used is that you are not referring to them in your code for evaluation of the Shift key or mouse position relative to control at the point of execution.

So, go ahead and use them if you want, example:


Private Sub OptionButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim ShiftSpeak$
If Val(Shift) = 0 Then
ShiftSpeak = "your keyboard's Shift button was not pressed."
Else
ShiftSpeak = "your keyboard's Shift button was pressed."
End If
MsgBox _
"When you clicked the mouse," & vbCrLf & _
ShiftSpeak & vbCrLf & vbCrLf & _
"Regarding the mouse's location relative to OptionButton1:" & vbCrLf & _
"Mouse position as distance from left: " & Val(X) _
& vbCrLf & _
"Mouse position as distance from top: " & Val(Y), _
64, "MouseDown info for OptionButton1"
End Sub
 
Upvote 0
Gotta Tom - you hadn't used them, so I wasn't sure what they were. So if i understand you correctly, in this (MouseDown) event, all of those parameters are available to me. Is that it?

Gene


I don't know what you mean by "that are not used". The only reason those parameters would not be used is that you are not referring to them in your code for evaluation of the Shift key or mouse position relative to control at the point of execution.

So, go ahead and use them if you want, example:


Private Sub OptionButton1_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Dim ShiftSpeak$
If Val(Shift) = 0 Then
ShiftSpeak = "your keyboard's Shift button was not pressed."
Else
ShiftSpeak = "your keyboard's Shift button was pressed."
End If
MsgBox _
"When you clicked the mouse," & vbCrLf & _
ShiftSpeak & vbCrLf & vbCrLf & _
"Regarding the mouse's location relative to OptionButton1:" & vbCrLf & _
"Mouse position as distance from left: " & Val(X) _
& vbCrLf & _
"Mouse position as distance from top: " & Val(Y), _
64, "MouseDown info for OptionButton1"
End Sub
 
Upvote 0
mortgageman said:
So if i understand you correctly, in this (MouseDown) event, all of those parameters are available to me. Is that it?
Yep - - they are available to you, to me, and everyone, they are equal opportunity parameters, standard with the OptionButton control's mousedown event for whoever is inclined to invoke their coded services.
 
Upvote 0

Forum statistics

Threads
1,214,406
Messages
6,119,330
Members
448,888
Latest member
Arle8907

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top