PopupMenu Method

See AlsovbmthPopupMenuSee                 ExamplevbmthPopupMenuEx>Low

Description

Displays a pop-up menu on a form at the current mouse location, or at specified coordinates.

Syntax

[form.]PopupMenu menuname [, flags [, x [, y] ] ]

Remarks

The PopupMenu method has these parts:

Part                 Description

 

menuname        The name of the pop-up menu to be displayed.  The specified menu must have at least one submenu.

flags                 Defines the location and behavior of a pop-up menu.

x                      Specifies the x coordinate where the pop-up menu is to be displayed.

y                      Specifies the y coordinate where the pop-up menu is to be displayed.

 

 

You specify the x, y coordinates using the scale mode of the specified form.  The x, y coordinates define where the pop-up is displayed relative to the specified form.  For example, the following code displays a pop-up menu in the upper-left corner of Form2 when the user clicks Form1:

' User clicks Form1
Sub Form_Click ()
  ' Display pop-up menu in upper-left corner of Form2.
  Form2.PopupMenu mnuAction, POPUPMENU_LEFTALIGN, 0, 0
End Sub

 

If the x, y coordinates are not included, the pop-up menu is displayed at the current location of the mouse pointer.

The following tables describe the possible values for flags:

Location constant                 Value               Description

 

POPUPMENU_LEFTALIGN        0                   (Default) The left side of the pop-up menu is at x.

POPUPMENU_CENTERALIGN  4                   The pop-up menu is centered at x.

POPUPMENU_RIGHTALIGN     8                   The right side of the pop-up menu is at x.

 

Behavior constant                 Value               Description

 

POPUPMENU_LEFTBUTTON    0                   (Default) The pop-up menu recognizes when the user clicks a menu item with the left mouse button only.

POPUPMENU_RIGHTBUTTON 2                   The pop-up menu recognizes when the user clicks a menu item with either the right or left mouse button.

 

Note   The flags parameter has no effect on applications running under Microsoft Windows version 3.0.

 

To specify flags, you can combine one constant from each group using the Or operator.  For example:

PopupMenu mnuEdit, POPUPMENU_RIGHTALIGN Or POPUPMENU_RIGHTBUTTON, xloc, yloc

 

When you display a pop-up menu, the code following the call to the PopupMenu method does not run until the user either selects an item in the menu (in which case the code for that menu's Click event is executed before control returns to the code following the PopupMenu statement), or cancels the menu.  In addition, only one pop-up menu can be displayed at a time.  Therefore, calls to this method are ignored if a pop-up menu is already displayed or if a pull-down menu is currently active.

A pop-up menu that is not visible in the menu bar because its Visible property is False in the Menu Design window can still be displayed, because the Visible property of the specified menu is ignored when Visual Basic displays a pop-up menu.

To display a pop-up menu when the user clicks the right mouse button, use the MouseDown event.

 

Note   Symbolic constants for the PopupMenu method parts can be found in the Visual Basic file CONSTANT.TXT.  When placed in any module in a project, the symbolic names can be used in all your form and code modules.