Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

Chapter 4 Working with Menus, Toolbars, and Dialog Boxes 117



  1. Close the program.


The application terminates, and the Visual Studio IDE appears.
That’s it! You’ve learned several important commands and techniques for creating menus,
toolbars, and dialog boxes in your programs. After you learn more about program code,
you’ll be able to create very sophisticated user interfaces in your own programs.

Adding Nonstandard Dialog Boxes to Programs
OK, you’ve gotten this far—but what if you need to add a dialog box to your program
that isn’t provided by one of the eight dialog box controls in Visual Studio? Unique
dialog boxes pop up all the time in programs, right? No problem—but you’ll need to
spend a little time building the custom dialog box in the Visual Studio IDE. As you’ll
learn in future chapters, a Visual Basic program can use more than one form to receive
and display information. To create nonstandard dialog boxes, you need to add new forms
to your program, add input and output objects, and process the dialog box clicks in your
program code. (These techniques will be discussed in Chapter 14, “Managing Windows
Forms and Controls at Run Time .”) In Chapter 5, “Visual Basic Variables and Formulas, and
the .NET Framework,” you’ll learn how to use two handy dialog boxes that are specifically
designed for receiving text input (InputBox) and displaying text output (MsgBox). These
dialog boxes help bridge the gap between the dialog box controls and the dialog boxes
that you need to create on your own.

One Step Further: Assigning Shortcut Keys to Menus


The MenuStrip control lets you assign shortcut keys to your menus. Shortcut keys are key
combinations that a user can press to activate a command without using the menu bar.
For example, on a typical Edit menu in a Windows application, such as Word, you can copy
selected text to the Clipboard by pressing CTRL+C. With the MenuStrip control’s ShortcutKeys
property, you can customize this setting. Try assigning two shortcut keys to the Clock menu
in the Menu program now.

Assign shortcut keys to the Clock menu


  1. Make sure that your program has stopped running and is in design mode.


You can modify a program only when it isn’t running. (For an exception to this rule,
see Chapter 8: “Debugging Visual Basic Programs .”)


  1. Click the Clock menu, and then click the Time command to highlight it.


Before you set the shortcut key for a menu command, you must select it. You assign
a shortcut key by setting the ShortcutKeys property for the command by using the
Properties window. The menu strip object provides an easy way for you to do this.
Free download pdf