Visual Basic Reference

Visual Studio 6.0

PopupMenu Method

See Also    Example    Applies To

Displays a pop-up menu on an MDIForm or Form object at the current mouse location or at specified coordinates. Doesn't support named arguments.

Syntax

object.PopupMenu menuname, flags, x, y, boldcommand

The PopupMenu method syntax has these parts:

Part Description
object Optional. An object expression that evaluates to an object in the Applies To list. If object is omitted, the form with the focus is assumed to be object.
Menuname Required. The name of the pop-up menu to be displayed. The specified menu must have at least one submenu.
Flags Optional. A value or constant that specifies the location and behavior of a pop-up menu, as described in Settings.
X Optional. Specifies the x-coordinate where the pop-up menu is displayed. If omitted, the mouse coordinate is used.
Y Optional. Specifies the y-coordinate where the pop-up menu is displayed. If omitted, the mouse coordinate is used.
boldcommand Optional. Specifies the name of a menu control in the pop-up menu to display its caption in bold text. If omitted, no controls in the pop-up menu appear in bold.

Settings

The settings for flags are:

Constant (location) Value Description
vbPopupMenuLeftAlign 0 (Default) The left side of the pop-up menu is located at x.
vbPopupMenuCenterAlign 4 The pop-up menu is centered at x.
vbPopupMenuRightAlign 8 The right side of the pop-up menu is located at x.

Constant (behavior) Value Description
vbPopupMenuLeftButton 0 (Default) An item on the pop-up menu reacts to a mouse click only when you use the left mouse button.
vbPopupMenuRightButton 2 An item on the pop-up menu reacts to a mouse click when you use either the right or the left mouse button.

Remarks

These constants are listed in the Visual Basic (VB) object library in the Object Browser.

You specify the unit of measure for the x and y coordinates using the ScaleMode property. The x and y coordinates define where the pop-up is displayed relative to the specified form. If the x and y coordinates aren't included, the pop-up menu is displayed at the current location of the mouse pointer.

When you display a pop-up menu, the code following the call to the PopupMenu method isn't executed until the user either chooses a command from the menu (in which case the code for that command's Click event is executed before 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 open.

Show: