Click to See Complete Forum and Search --> : Right Click Menus?
Smie
Dec 3rd, 1999, 04:04 AM
Is it possible to make a menu popup within vb when you right-click of something. Same idea as when you rightclick the windows desktop, but just more customizable? if so is there a tutorial for this? can someone help me out? thanx!
MartinLiss
Dec 3rd, 1999, 05:17 AM
Sure. Add a menu to your form which has the top level (which I've called mnuFirstItem) enabled but not visible. Then add as many menu items under that one as you like, all of them being visible (don't worry they won't show up until you want them to). Then add code like this to your form and any object you want to have popup help.Option Explicit
Private ControlClicked As Control
Private Sub MyObject_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Button = vbRightButton Then
Set ControlClicked = MyObject
PopupMenu mnuFirstItem
End If
Set ControlClicked = Nothing
End Sub
------------------
Marty
Ruchi
Dec 5th, 1999, 12:04 PM
Yes, it is possible to make a pop-up menu! In the Menu Editor, it should look like this one.
PopUp
...Blue
...Green
PopUp displays a pop-up Menu. When you right-click the mouse, pop-up menu appears.
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbrightButton Then
Call PopupMenu(mnuPopUp)
End If
End Sub
Private Sub mnuBlue_Click()
Label1.BackColor = vbBlue
End Sub
Private Sub mnuGreen_Click()
Label1.BackColor = vbGreen
End Sub
Hope this helps.
Ruchi
netSurfer
Feb 17th, 2003, 01:26 PM
this is something I've been trying to remember how to do for awhile so I'm glad to have found this thread. But I have one further question:
How can I add my options to the existing menu that pops up?
For example: I want to add a couple options to the existing menu that pops up when you right click in a text control.
I fond another thread that talked about using API calls but I'd really rather not go to that extreme. Is that really the only way to customize the existing menu?
If re-create the menu - how do I figure out what code to use?
The existing menu has the following options:
Undo, cut, copy, paste, delete and select all. How do I know what code to use to do the exact same things?
I know that may sound like a stupid thing not to know but I've taken a several month long break from VB and I find that I've forgotten some things that I used to know so any help is appreciated.
Thanks.
James Stanich
Feb 17th, 2003, 01:33 PM
VB Example - Suppress Windows Auto PopupMenu (http://www.galahtech.com/forums/showthread.php?s=&threadid=1301&highlight=suppress)
This example shows how to diplay your own popup menu, instead of Windows standard one. Is this what you mean?
netSurfer
Feb 17th, 2003, 01:41 PM
instead of suppressing the existing menu - I want to add a couple items to it.
But I did bookmark the site you provided some interesting examples. Thanks.
James Stanich
Feb 17th, 2003, 01:43 PM
Originally posted by netSurfer
instead of suppressing the existing menu - I want to add a couple items to it.
But I did bookmark the site you provided some interesting examples. Thanks.
What I meant was to recreate the menu, and add your own specialty items...;)
netSurfer
Feb 17th, 2003, 01:58 PM
i was hoping to avoid having to recreate it - plus I"m not sure the best way to do it if I have to. Would I have to use API calls to do the existing menu items?
nightshift
Feb 24th, 2003, 10:00 PM
This is the code im using:
Global ControlClicked As Control
Private Sub txtArticle_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
Set ControlClicked = txtArticle
PopupMenu mnuArticle
End If
Set ControlClicked = Nothing
End Sub
This works fine on every control i have tested it with apart from the textbox control...
when you rightclick in the textbox the standard windows rightclick menu pops up in the top left hand corner of the screen, then if you rightclick again the correct menu appears... anyone had this problem before and/or know how to fix it?
I had a look at the code to suppress the windows menu (thanks james) but it seems more complicated than i need...
So is there an easier way to get around this problem?
Thanks in advance for any help offered.
Nightshift
netSurfer
Feb 24th, 2003, 11:54 PM
I gave up waiting for an answer and just re-created the whole menu. Everything but the UNDO at least. The cut, copy, paste etc were easy to do so I just made my own menu and called that. I did notive that you have to right click twice in order for my menu to up - the first click doens't do anything. I don't get the regular menu poping up at all - just my custom one. And I did it just like you have. Sorry couldn't tell you anything else.
John McKernan
Feb 25th, 2003, 12:03 AM
This works fine on every control i have tested it with apart from the textbox control...
when you rightclick in the textbox the standard windows rightclick menu pops up in the top left hand corner of the screen, then if you rightclick again the correct menu appears... anyone had this problem before and/or know how to fix it?
I had a look at the code to suppress the windows menu (thanks james) but it seems more complicated than i need...
So is there an easier way to get around this problem?
I've seen this several places. I've tested it, but never used it in a program.
Private Sub txtArticle_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
txtArticle.Enabled = False
txtArticle.Enabled = True
PopupMenu mnuArticle
End If
End Sub
nightshift
Feb 25th, 2003, 01:35 AM
Thanks John, That worked a treat :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.