CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Context menus

  1. #1
    Join Date
    Sep 2000
    Posts
    200

    Context menus

    I have 2 DataGrids on frmMain. I want a different menu to popup when the user right clicks . . . depending on which DataGrid the mouse is over. Can you create multiple menus (completely different) at design time? Thanks for any input.


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: Context menus

    Sure you can, just create them using the Menu editor, and show them using the PopupMenu method in the Mousedown event of the control. Some controls however have a default popup menu. I'm not sure about datagrids, but anyway, setting the control to disabled and back to enabled most of the time eliminates this behaviour.

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Sep 2000
    Posts
    200

    Re: Context menus

    Tom, thanks for your quick reply. But, say you have used the Menu Editor & created a menu for frmForm1. How do you use the Menu Editor and create another menu (to be used as a popup)? When I click the Menu Editor, the 1st menu is there . . . and I can't see how to create another unless I create another form. (?)

    Thanks in advance for your help.
    John


  4. #4
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Context menus

    A short example of two popup menus
    Start a new project.
    start the menu editor. Create menu items like so
    Popup Menu 1 (mnuPopup1) visible = False
    ....> popup Sub 1 (mnuPopupSub1)
    Popup Menu 2 (mnuPopup2) Visible = False
    ....> Popup Sub 2 (mnuPopupSub2

    Add two command buttons. Here is the code for the command buttons

    option Explicit

    private Sub Command1_Click()
    PopupMenu mnuPopup1
    End Sub

    private Sub Command2_Click()
    PopupMenu mnuPopup2
    End Sub




    John G

  5. #5
    Join Date
    Sep 2000
    Posts
    200

    Re: Context menus

    Excellent! Things are so simple when you know the answers.

    Thanks,
    John


  6. #6
    Join Date
    Sep 2000
    Posts
    200

    Re: Context menus

    Tom, thanks. I finally see. I have been thinking that when you click on Menu Editor, you are only working with one menu . . .
    Thanks,
    John


  7. #7
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Context menus

    <de-lurk>

    You might want to checkout the excellent article on this site at :

    http://www.codeguru.com/vb/articles/2043.shtml

    - it shows how to create dynamic menus at run time using a class module - very nice compact concise code.

    </de-lurk>


    Chris Eastwood
    VBCodeLibrary - http://www.vbcodelibrary.com

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

Featured