![](http://imgdetail.ebookreading.net/software_development/33/9780470596906/9780470596906__stephens-c-programming__9780470596906__bg65.png)
4. Repeat step 2 for the Format ➪ Background Color menu items, making them set the
TextBox’s BackColor property to Pink, LightGreen, and LightBlue.
5. Double-click the Format ➪ Font ➪ Small menu item and type the highlighted line in the
following code so the event handler looks like this:
private void formatFontSmallMenuItem_Click(object sender, EventArgs e)
{
contentsTextBox.Font = formatFontSmallMenuItem.Font;
}
6. Repeat step 5 for the Normal and Large menu items.
Make the context menu duplicate the main menu’s Format submenu.
➤
Do either 1 or 2:
1. Build the structure from scratch. (This is straightforward but slow.)
a. Click the ContextMenuStrip in the Component Tray to open it for editing.
b. Use steps similar to the ones you used to build the main menu’s structure
to build the context menu’s structure. End context menu item names with
ContextMenuItem as in colorRedContextMenuItem.
2. Copy the Format menu’s structure. (This is sneakier and faster, and therefore
much cooler!)
a. Click the MenuStrip in the Component Tray to open it for editing. Expand the
Format menu. Click the Color item and then shift-click the Font item to select all
of the menu’s items. Press [Ctrl]+C to copy the menu items into the clipboard.
b. Click the ContextMenuStrip in the Component Tray to open it for editing. Press
[Ctrl]+V to paste the menu items into the context menu.
c. Give appropriate names to the new menu items.
Attach the context menu items to the event handlers used by the main menu.
➤
1. Open the ContextMenuStrip for editing. Expand the Color submenu and click the Red
item. In the Properties window, click the events button (the lightning bolt) to see the
menu item’s events. Select the
Click event, click the dropdown arrow to the right, and
select
formatColorRedMenuItem_Click.
2. Repeat step 1 for the ContextMenuStrip’s other items, attaching them to the correct
event handlers.
Attach the context menu to the
➤
TextBox.
1. Click the TextBox. In the Properties window, set its ContextMenuStrip property to
the
ContextMenuStrip formatContextMenu.
Please select Lesson 5 on the DVD to view the video that accompanies this lesson.
596906c05.indd 63 4/7/10 12:31:53 PM