Making Menus


Most applications use menus to help people find options that they want. In Visual basic menus are so easy that there is not excuse for not having one where you need it. Just about the only type of application that does not need a menu is a game. In this tutorial we will make a rather useless menu that just shows how they work.

First create a new standard project. Right click the form and select the menu editor.

Getting the menu editor dialog

The menu editor

The Caption field is where you put the visible text that will appear on the menu. If you put an & before a letter then that letter will be used when users navigate the menu using the keyboard. The name is the name that will be used in the code. It is common practice to use mnu as a prefix for the name eg. mnuFile.

First create an item with the caption &File with the name mnuFile. Now click next to move onto the next item. To put an item inside another you have to click the right arrow The arrows and it will indent. Enter 3 more items (using an & if you wish): Save, Open and Exit. These should all be indented.

Now click the left arrow to move back to the first level and create a Help item. Click the right arrow again and create About. Now your window should look like this:

The complete menu editor view

Now you can click OK. You will see your menu appear at the top of the form. Don't worry about it being white as it will become the right colour when you run the program. Now we are going to create the Exit function. To get to the Exit click event you should click File then Exit. The code window will appear. All we want to do is end the program so just type 'End'. Now run the program and the menus will be there. Try clicking Exit when you have finished looking at the menus.


© Jonathan Waller 2005; QuantumState Visual Basic