Objectives
•
•
Chapter 5
•
•
• Menus, Common
Dialog Boxes, Sub
Procedures, and
Function
Procedures
McGraw-Hill
5-2
Copyr ight © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.
Defining Menus (1 of 2)
Menus
•
•
Menu Bar
• Contains menus which drop down to display list of menu items
– Can be used in place of or in addition to buttons
•
•
Create menus and submenus for program control.
Display and use the Window s common dialog boxes. Create context menus for controls and the form.
Write reusable code in sub procedures and function procedures and call the procedures from other locations.
to execute a procedure
– Menu items are controls with properties and events.
•
Easy to create menus for a Window s form using the Visual Studio environment’s Menu Designer
Menus w ill look and behave like standard
Window s menus.
MenuStrip component is added to a form.
MenuStrip is a container to w hich ToolStripMenuItems,
ToolStripComboBoxes,
ToolStripSeparators, and
ToolStripTextBoxes can be added. 5-3
5-4
The Text Property
Defining Menus (2 of 2)
•
•
Holds the words that appear on the screen — like the
Text property of a button or label
To conform to Windows standards, the first menu’s Text property should be File, with a keyboard access key.
• Use the ampersand (&) in the text to specif y the key
The MenuStrip component appears in the component tray below the f orm and the Menu
Designer allows y ou to begin ty ping the text for the menu items. •
5-5
to use f or key board access.
Enter and change the Text property for each menu and menu item using the Menu Designer or make the changes in the Text property using the Properties window. 5-6
1
7/31/2014
The Name Property
•
•
The MenuStrip Items Collection
•
The File menu item that is added is automatically named FileToolStripMenuItem.
The items are named so w ell that there w on’t be a need to change the Name property of any menu component. • If the Text property is