Previous Page
Next Page

Chapter 21 Quick Reference

To

Do this

Create a menu for a form.

Add a MenuStrip control to the form.

Add menu items to a menu.

Click the MenuStrip control at the bottom of the form. Click the Type Here caption on the menu strip of the form and type the name of the menu item. To add additional items, replace the other Type Here captions that appear. You can add an access key to a menu item by prefixing the corresponding letter with a & character.

Create a separator bar in a menu.

Create a menu item by replacing the Type Here caption with a minus sign (–).

Add a shortcut key to a menu item.

Select the menu item, and then set the ShortcutKeys property to the required key combination in the Properties window.

Enable or disable a menu item.

At design time, set the Enabled property to True or False in the Properties window. At run time, assign the value true or false to the Enabled property of the menu item. For example:

printToolStripmenuItem.Enabled = true;

Perform an action when the user clicks a menu item.

Select the menu item. In the Properties window, click Events. In the Click event, type the name of an event method. Add your code to the event method.

Create a pop-up menu.

Add a ContextMenuStrip control to the form. Add items to the pop-up menu just as you add items to a main menu.

Associate a pop- up menu with a form or control.

Set the ContextMenuStrip property of the form or control to refer to the pop-up menu itself.

Create a pop-up menu dynamically.

Create an array of menu items. Populate the array. Create the pop-up menu by using the array. Set the ContextMenuStrip property of the form or control to refer to the pop-up menu.

Prompt the user for the name of a file to save.

Use a SaveFileDialog control. Display the dialog box by using the ShowDialog method. When the dialog box closes, the FileName property contains the name of the file selected by the user, and you can use the OpenFile method of the dialog box to read and write the file.

Send a document to a printer.

Use a PrintDialog control to prompt the user for the printer to use. Use the PrintPage event of a PrintDocument control to actually send the document to the printer.


Previous Page
Next Page