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!
Printable View
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!
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.------------------Code: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
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.
Hope this helps.Code:
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
Ruchi
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.
VB Example - Suppress Windows Auto PopupMenu
This example shows how to diplay your own popup menu, instead of Windows standard one. Is this what you mean?
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...;)Quote:
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.
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?
This is the code im using:
VB Code:
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
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.
I've seen this several places. I've tested it, but never used it in a program.Quote:
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?
VB Code:
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
Thanks John, That worked a treat :)