[ Using VB ]
Menus are a good way to organize commands and save
space when used correctly. Visual Basic gives us an easy way to create and edit
these menus using the Menu Editor. With the menu editor, you can:
Modify Existing Menus
Add Special Effects
To access the menu editor, open the form you want the menu on and click on Tools - Menu Editor in the Visual Basic Menu.
In the Caption field, type in the name that will appear in the menu (Usually, the first one is File). Then hit tab and type in a name for it (Most programmers use the standard naming convention "mnu" to name the menu. A good name for File would be mnuFile). Just click next when you've done that and the text boxes will clear. Type in another caption and name and this time, click the right arrow. This will indent the line so that the menu editor knows that this line is a command under the File menu.
If you need to put a dividing line in the menu like in the following example, just put "-" in the caption field. This is helpful for dividing groups of commands like the open options, save options, and exit.
In the above menu, you can see that the "Undo" command is disabled. If you want to make one of your commands start out disabled, you can uncheck the "Enabled" check box in the menu editor. When you want the command to be enabled, you can use the Object.Enabled method. (ex: mnuFileUndo.Enabled = True)
Another special affect that you may have seen in programs is the Checked property. When enabled, the command in your menu will have a check mark placed next to it. See the following example:
The checked property works just like the enabled. You can
either select the check box in the menu editor to start the program with it checked, or
you can use code.
(Ex: mnuFontBold.checked = True)
Once you've become good at making menus, there are several more things you can do with them to make your program have more of a professional feel. You can create pop-up menus that will appear when the user right clicks on the form. This is extremely helpful for easy menu access by the user.
To make a pop up menu, first create the menu you want to pop up. Then, write the code behind the form that will pop up the menu you want.
In this example, the user won't have to go all the way up to the menu in order to access it. The following pops up this menu wherever the mouse is on the form when the user right clicks.
Private Sub Form_MouseDown(Button As
Integer, Shift As Integer, X As
Single, Y As Single)
If Button = 2 Then 'Checks that the user right clicked
PopupMenu mnuFile 'Shows the selected menu