Page 213 - Open Soource Technologies 304.indd
P. 213
Unit 9: Menus and Dialog Boxes
Figure 9.5: Pop-up Menu.
Any menu that has at least one menu item can be displayed at run time as a pop-up menu. To
display a pop-up menu, use the PopupMenu method. This method uses the following syntax:
[object.]PopupMenu menuname [, flags [,x [, y [, boldcommand]
For example, the following code displays a menu named mnuFile when the user clicks a form
with the right mouse button. You can use the MouseUp or MouseDown event t detect when the
user clicks the right mouse button, although the standard is to use the MouseUp event:
Private Sub Form_MouseUp (Button As Integer, Shift As _
Integer, X As Single, Y As Single)
If Button = 2 Then ‘ Check if right mouse button
‘ was clicked.
PopupMenu mnuFile ‘ Display the File menu as a
‘ pop-up menu.
End If
End Sub
Any code following a call to the PopupMenu method is not run until the user selects an item
in the menu or cancels the menu.
Only one pop-up menu can be displayed at a time. While a pop-up menu is
displayed, calls to the PopupMenu method are ignored. Calls to the PopupMenu
method are also ignored whenever a menu control is active.
Often we want a pop-up menu to access options that are not usually available on the menu bar.
To create a menu that will not display on the menu bar, make the top-level menu item invisible
at design time (make sure the Visible check box in the Menu Editor is not checked). When Visual
Basic displays a pop-up menu, the visible property of the specified top-level menu is ignored.
LOVELY PROFESSIONAL UNIVERSITY 207