Results 1 to 12 of 12

Thread: Right Click Menus?

  1. #1

    Thread Starter
    Addicted Member Smie's Avatar
    Join Date
    Jun 1999
    Location
    Columbus, OH
    Posts
    249

    Post

    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!

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    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

  3. #3
    Member
    Join Date
    Dec 1999
    Posts
    37

    Post

    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

  4. #4
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    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.

  5. #5
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    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....

  6. #6
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359

    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.

  7. #7
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    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....

  8. #8
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359
    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?

  9. #9
    Lively Member
    Join Date
    Nov 2002
    Location
    Perth - Australia
    Posts
    105
    This is the code im using:

    VB Code:
    1. Global ControlClicked As Control
    2.  
    3.  
    4. Private Sub txtArticle_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    5.     If Button = vbRightButton Then
    6.         Set ControlClicked = txtArticle
    7.         PopupMenu mnuArticle
    8.     End If
    9.     Set ControlClicked = Nothing
    10. 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

  10. #10
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Calgary Alberta
    Posts
    359
    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.

  11. #11
    Frenzied Member John McKernan's Avatar
    Join Date
    Jan 2002
    Location
    SE PA
    Posts
    1,295
    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:
    1. Private Sub txtArticle_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     If Button = vbRightButton Then
    3.         txtArticle.Enabled = False
    4.         txtArticle.Enabled = True
    5.         PopupMenu mnuArticle
    6.     End If
    7. End Sub

  12. #12
    Lively Member
    Join Date
    Nov 2002
    Location
    Perth - Australia
    Posts
    105
    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
  •  



Click Here to Expand Forum to Full Width