|
-
Dec 3rd, 1999, 05:04 AM
#1
Thread Starter
Addicted Member
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!
-
Dec 3rd, 1999, 06:17 AM
#2
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
-
Dec 5th, 1999, 01:04 PM
#3
Member
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.
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
Hope this helps.
Ruchi
-
Feb 17th, 2003, 02:26 PM
#4
Hyperactive Member
I know this is an old thread but still
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.
-
Feb 17th, 2003, 02:33 PM
#5
PowerPoster
Well
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?
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Feb 17th, 2003, 02:41 PM
#6
Hyperactive Member
not quite what I wanted
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.
-
Feb 17th, 2003, 02:43 PM
#7
PowerPoster
Re: not quite what I wanted
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...
Remaining quiet down here !!!
BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....
-
Feb 17th, 2003, 02:58 PM
#8
Hyperactive Member
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?
-
Feb 24th, 2003, 11:00 PM
#9
Lively Member
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
-
Feb 25th, 2003, 12:54 AM
#10
Hyperactive Member
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.
-
Feb 25th, 2003, 01:03 AM
#11
Frenzied Member
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.
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
-
Feb 25th, 2003, 02:35 AM
#12
Lively Member
Thanks John, That worked a treat
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
|