Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Right Click 1

Status
Not open for further replies.

AdamVerellen

IS-IT--Management
Sep 20, 2002
39
CA
I created a form that is full of command buttons. I want to bring a menu up on right click. Got the menu working, right click working. The problem is the button needs focus in order for the right click to work. I've tried differnet things, mousedown, mouseup, click. Just can't seem to get it to work the way I had thought it would.

Adam
 
THe event you need it MouseDown or MouseUp..

And then you need to test the button argument..
e.g.


Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
' dosomething, bring up an menu... whateverr
End If
End Sub
 
Sorry need to read better...

I dont' quite follow what you are having a problem with..
If you right click a button it automaticly gets focus..

What are you trying to achieve exactly.

Rob
 
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then PopupMenu MenuName
End Sub


-bclt
 
I use the mouse up event like this,
Code:
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
'// Show the popup menu.
   If Button = vbRightButton Then Form1.PopupMenu mnuPopup
End Sub
Where 'mnuPopup' is a defined root level menu in the menu editor.


zemp
 
For the Form MouseUp event, do I not have to click on the form. I have 40 buttons covering the whole form.
 
That is only an example, use the buttons mouseup event.

zemp
 
Zemp.... I have that now.
The way its working now, I have to left click on the button to get focus, then right click to get the menu
 
Just call the command button's setfocus method before calling the popup menu in the mouseup event. It shouldn't need focus to popup the menu though.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Before I started with the post.
I have a form with 40 command buttons on it.
The buttons come from the MS Forms library.
They cover the whole form on load based on screen size.
I wanted to spice it up with having the user being able to change the button colours. So I thought right click the button and bring up a menu.
All that works expect. If I right click I get no menu.
If I left click first, then right click I get the menu.
The left click I wanted to bring up another function.

That's as clear as I can be.
 
Here is a chunk of what I used to get it to work.
DrJavaJoe, you got me thinking about setfocus.
I'm not sure if this is what you meant, but it works.
My next question is, the mousemove event, do you figure it eats the system resources up?


Thanks

Private Sub Command1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = vbRightButton Then
iTempButtonIndex = Index
PopupMenu mnuRightClick
End If

If Button = vbLeftButton Then
Select Case Index

Case 39
frmButtonsDownTime.Hide

Case Else
frmEnterValue.Caption = "Enter Downtime in Minutes."
frmEnterValue.txtValue.MaxLength = 3
frmEnterValue.Command3(10).Enabled = False
frmEnterValue.Show vbModal
End Select
End If

End Sub

Private Sub Command1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
Command1(Index).SetFocus

End Sub



 
ahhh, MS Forms library, you never mentioned that. If you want to change the color of the standard button change it's style property to graphical, then you won't have this problem. Also you won't have the problem of distributing the MS Forms Library which is not allowed.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Oh, and all the systems I will be putting this on have Office installed already. From what I can tell it is included with Office
 
Ok then use the standard checkbox also with it's style property set to graphical, it has a forecolor property. Just be sure to uncheck it in it's click event and it will behave and look just like a command button.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
If that is the case then you have no problem, except with the focus problem;-)



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Focus problem is solved with mousemove.
I check which button I'm over, and setfocus.
Works great.
Not sure if I will have problems down the road using mousemove, but I'll jump them when I get there.

Thanks for your help
 
The problem I see with it is that as you move the mouse across the form your focus keeps changing. Also, let's say you are typing in a textbox and bump the mouse and focus changes and then hit the space key, that will cause the buttons click event to fire which may be a problem. My 2 cents.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top