We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 55,161 times

Related Categories

Popup Menu Example

This example shows you how to display a popup menu...

First, you need to add a number of controls:

Type Name Caption
Label lblPopup Right click for popup menu
Label lblDefaultPopup Right click for popup menu with default item
Label lblShowPopupAtX Right click here to display popup at X
Label lblX X
Menu mnuTest Test Menu
Menu mnuTestItem1 Test Item 1
Menu mnuTestItem2 Test Item 2

Make sure that mnuTestItem 1 and 2 are sub menus of mnuTest. Now, add the code below, run your project, and try right clicking on each of the labels.

Private Sub lblDefaultPopup_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then '// is right button?
        PopupMenu mnuTest, , , , mnuTestItem1 '// display popup menu
    End If
End Sub
Private Sub lblPopUp_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then '// is right button?
        PopupMenu mnuTest '// show popup
    End If
End Sub
Private Sub cmdHidePopup_Click()
    mnuTest.Visible = False '// hide the popup menu from the main menu bar
End Sub
Private Sub lblShowPopupAtX_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then
        '// get the coordinates of the X label (x and y)
        PopupMenu mnuTest, , lblX.Left, lblX.Top '// display menu
    End If
End Sub

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments

  • Run-time error '428'

    Posted by silkroute9009 on 05 Feb 2004

    hii

    i was looking for the solution of this, i got at this thread but it was not answered here
    so i put that here if somebody else is looking for it

    :)

  • Posted by HyperHacker on 04 Feb 2004

    Heh, thanks, but I removed the popup menu a while ago. ;)

  • Posted by silkroute9009 on 01 Feb 2004

    Hello

    you can get rid of that error if you use the code below -

    Me.PopupMenu mPopupSys.Item(0)

    it works

    :)

  • Run-time error '428':

    Posted by HyperHacker on 19 Jul 2003

    Popup menu must have at least one submenu
    ...Why would it say that, when my menu has one option and 2 submenus loaded with them? (Though the one option is just to try to make it work :p I'd like to g...