Home and Learn: VB Net Course

Add Shorcuts to your Menu Items

This tutorial assumes that you have completed the first one.

In the previous tutorial, you learned how to add Sub Menus to your VB .NET forms. In this part, you'll see how to add shortcuts to your menu items

Underline Shortcut

To add an underline, do this:

  1. Click on your New menu item once. This will select it
  2. Position your cursor before the "N" of New
  3. Type an ampersand symbol (&)

  1. Hit the return key on your keyboard
  2. You should see this:

Notice that "N" of New is now underlined. If you want an underline shortcut, the ampersand character should be typed before the letter you want underlined.

Add underlines for the "F" of you File menu, the "O" of Open, the "S" of Save, and the "X" of Exit. When you're done, your menu should look like this one:

Time to see if your shortcut works. Run your programme. To use the underline shortcuts on menus, you first hold down the Alt key on your keyboard. Then type the underline character.

  1. Hold down the Alt key while your programme is running (You might not be able to see the underlines until you press the Alt key.)
  2. Press the letter "F" on your keyboard
  3. Then press the letter "X" (for the Exit menu)
  4. Your programme should close down

All that and you didn't have to write a single line of code!

Key combination shortcuts

A key combination shortcut is one that appears at the end of a menu item (Ctrl + X, for example). You can easily add this option to your own programmes. So try this:

  1. In Design time, select the Exit item on your menu
  2. Look at the properties box on the right
  3. Locate the ShortcutKeys item:

ShortcutKeys Property in VB NET

  1. Click the down arrow to reveal the following:

The Modifier is the key you press with your shortcut. For example, the CTRL key then the "X" key on your keyboard. Place a check inside the Ctrl box. Then select the letter "X" from the Key dropdown list, as in the next image:

Click back on your menu to see what it looks like:

Run your programme and test out the shortcut. Don't click the File menu. Just hold down the Ctrl key on your keyboard. Then press the letter X. Again, the programme will close down.

You can add these types of shortcuts to any menu item. Just remember to choose a different key stroke combination for each one. And don't have too many of them - they'll spoil the look of your menu!

In the next lesson, you'll learn how to add images next to the text on your menu items.

Back to the VB NET Contents Page


Buy the Book of this Course

Email us: enquiry at homeandlearn.co.uk