97
Chapter 4
Working with Menus, Toolbars,
and Dialog Boxes
After completing this chapter, you will be able to:
n Add menus to your programs by using the MenuStrip control.
n Process menu and toolbar selections by using event procedures and the Code Editor.
n Add toolbars and buttons by using the ToolStrip control.
n Use the OpenFileDialog and ColorDialog controls to create standard dialog boxes.
n Add access keys and shortcut keys to menus.
In Chapter 3, “Working with Toolbox Controls,” you used several Microsoft Visual Studio
2010 controls to gather input from the user while he or she used a program. In this chapter,
you’ll learn how to present more choices to the user by creating professional-looking menus,
toolbars, and dialog boxes.
A menu is located on the menu bar and contains a list of related commands; a toolbar
contains buttons and other tools that perform useful work in a program. Most menu
and toolbar commands are executed immediately after they’re clicked; for example, when
the user clicks the Copy command on the Edit menu, information is copied to the Clipboard
immediately. If a menu command is followed by an ellipsis (... ), however, clicking the
command displays a dialog box requesting more information before the command is carried
out, and many toolbar buttons also display dialog boxes.
In this chapter, you’ll learn how to use the MenuStrip and ToolStrip controls to add
a professional look to your application’s user interface. You’ll also learn how to process menu,
toolbar, and dialog box commands.
Adding Menus by Using the MenuStrip Control
The MenuStrip control is a tool that adds menus to your programs, which you can customize
with property settings in the Properties window. With MenuStrip, you can add new menus,
modify and reorder existing menus, and delete old menus. You can also create a standard
menu configuration automatically, and you can enhance your menus with special effects,
such as access keys, check marks, and keyboard shortcuts. The menus look perfect—just
like a professional Windows application—but MenuStrip creates only the visible part of your
menus and commands. You still need to write event procedures that process the menu
Table of Contents
Working with Menus, Toolbars, and Dialog Boxes............... 97
Adding Menus by Using the MenuStrip Control......................... 97
Adding Access Keys to Menu Commands............................... 99
Processing Menu Choices............................................ 102
Adding Toolbars with the ToolStrip Control............................ 107
Using Dialog Box Controls........................................... 110
Event Procedures That Manage Common
Dialog Boxes....................................................... 112
One Step Further: Assigning Shortcut Keys to Menus.................... 117
Chapter 4 Quick Reference........................................... 119