VB Logo

Pull Down and Popup Menus


Pull Down Menus

Pull down menus are used extensively in Windows applications. They have a number of advantages:

When building new applications in VB, existing menu conventions should be used unless there is a very good reason to depart from them.

Meus are created using the Menu Design Window found under the Window menu. This window can also be invoked by clicking on the icon on the toolbar.

The top half of the Menu Design Window contains the menu control properties. The lower half is the menu control list box, where the menu/submenu structures for the current form are built up. The above Menu Design Window produces the menu shown below.

When an item is typed in the Caption text box, it also appears in the menu control list box. Selecting an item in the list box allows its properties to be edited (in a similar way to editing properties of controls in the properties window).



Pop-up Menus

A pop-up menu is one that is displayed on top of a form and is not attached to the menu bar.

PopupMenu Method Example:

The code below displays a pop-up menu at the cursor location when the user clicks the right mouse button over a form. To try this example, create a form with a menu named “mnuFile” (“mnuFile” must have at least one submenu). Copy the code into the Declarations section of the form then run the application.

  Private Sub Form_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = 2 Then PopupMenu mnuFile

  End Sub

In the above example, the pop-up menu appears at the X, Y position of the cursor, when the right mouse button is pressed (Button = 2). Use VB Help to explore the flags that can be set to specify the behaviour of a pop-up menu.

Note: All controls are displayed relative to the co-ordinates of the parent object, so setting X and Y both to 0 displays a pop-up menu at the top left corner of the form.


Menu

Tutorials using pull-down menus:
Tutorial 5 (Menus and List manipulation)
Tutorial 14 (Multiple Document Interface)