Lesson 37: Creating Menus for VB Applications

Design professional menu systems for your VB6 applications

Key Takeaway

Professional menu systems enhance application usability and provide intuitive navigation for users.

Welcome to Lesson 37 of our Visual Basic 6 Tutorial! In this lesson, you'll learn how to create professional menu systems for your VB6 applications using both the Application Wizard and the Menu Editor.

37.1 Adding Menu Bar Using Visual Basic's Application Wizard

The easiest way to add a menu bar to your application is by using Visual Basic's Application Wizard. This wizard allows the user to insert fully customized standard Windows menu into his or her application.

Quick Setup

Rapidly create professional menus with minimal effort

Standard Patterns

Follow established Windows menu conventions

Pre-built Code

Includes functional code for common menu actions

Getting Started:

1 Launch Application Wizard

Click on the Application Wizard icon at the Visual Basic new project dialog box.

2 Configure Interface Type

Choose Single Document Interface (SDI) and enter your project name.

3 Select Menu Items

Check the menu items you want to include in your application.

4 Complete Wizard

Finish the wizard to generate your menu system with functional code.

New Project Window
Figure 37.1: New Project Window
Wizard Introduction
Figure 37.2: Application Wizard Introduction
Interface Type
Figure 37.3: Selecting Interface Type
Menu Selection
Figure 37.4: Menu Item Selection
Generated Menu
Figure 37.5: Generated Menu System

Important

The Application Wizard generates functional code for common actions like File Open, but you'll need to customize this code for your specific application requirements.

Customizing the File Open Functionality

Here's how to modify the File Open menu code to load images into an ImageBox:

FileOpenHandler.vb
Private Sub mnuFileOpen_Click()
Dim sFile As String
With dlgCommonDialog
    .DialogTitle = "Open"
    .CancelError = False
    ' Set the flags and attributes of the common dialog control
    .Filter = "Bitmaps(*.BMP)|*.BMP|Metafiles(*.WMF)|*.WMF|" & _
              "Jpeg Files(*.jpg)|*.jpg|GIF Files(*.gif)|*.gif|" & _
              "Icon Files(*.ico)|*.ico|All Files(*.*)|*.*"
    .ShowOpen
    Image1.Picture = LoadPicture(.FileName)
    If Len(.FileName) = 0 Then Exit Sub
    sFile = .FileName
End With
End Sub
                        
File Menu
Figure 37.6: File Menu Dropdown
Generated Code
Figure 37.7: Generated Code
Open Dialog
Figure 37.8: Open File Dialog
Image Selection
Figure 37.9: Image Selection Dialog
Image Loaded
Figure 37.10: Image Loaded in Application

37.2 Adding Menu Bar Using Menu Editor

For more control over your menu design, use the Menu Editor to create custom menu systems tailored to your application's needs.

Complete Control

Design menus precisely to your specifications

Custom Options

Create unique menu items not available in the wizard

Hierarchical Menus

Build multi-level menus with sub-items

Menu Editor Steps:

1 Access Menu Editor

Go to Tools > Menu Editor in the Visual Basic IDE.

2 Create Menu Items

Add menu items with captions and names (e.g., &File and mnuFile).

3 Add Submenus

Use the right arrow to create submenu items under main menus.

4 Write Event Handlers

Click menu items in the form to create and edit their code.

Menu Editor
Figure 37.11: Menu Editor Interface
Adding Menu Items
Figure 37.12: Adding Menu Items
Main Menu
Figure 37.13: Main Menu Items
Submenu Creation
Figure 37.14: Adding Submenu Items
Final Menu
Figure 37.15: Completed Menu System

Best Practice

Use ampersands (&) in menu captions to create keyboard shortcuts (e.g., &File creates Alt+F shortcut).

Lesson Summary

In this lesson, you've learned two approaches to creating professional menus for your VB6 applications:

Application Wizard

Quickly create standard menus with functional code

Menu Editor

Design custom menus with complete control over structure

Customization

Modify menu code to implement your application's functionality

Best Practices

Follow Windows UI conventions for intuitive user experience

Pro Tip

Combine both approaches - start with the Application Wizard for common menus, then use the Menu Editor to add custom items.

Next Lesson

Continue your VB6 journey with Lesson 38: Keyboard Handling.

Related Resources

VB6 Menu Design Guide

Official Microsoft documentation for menu design

View Resource

Advanced Menu Techniques

Learn to create context menus and toolbar integration

View Resource

Shortcut Keys

Implement keyboard shortcuts for menu items

View Resource

Menu Best Practices

Design menus that follow Windows UI guidelines

View Guide