![](http://imgdetail.ebookreading.net/software_development/33/9780470596906/9780470596906__stephens-c-programming__9780470596906__bg7c.png)
86
LESSON 7 Using RichTexTBoxes
private void editRedoMenuItem_Click(object sender, EventArgs e)
{
contentRichTextBox.Redo();
}
private void editCopyMenuItem_Click(object sender, EventArgs e)
{
contentRichTextBox.Copy();
}
private void editCutMenuItem_Click(object sender, EventArgs e)
{
contentRichTextBox.Cut();
}
private void editPasteMenuItem_Click(object sender, EventArgs e)
{
contentRichTextBox.Paste();
}
private void editDeleteMenuItem_Click(object sender, EventArgs e)
{
contentRichTextBox.SelectedText = “”;
}
private void editSelectAllMenuItem_Click(object sender, EventArgs e)
{
contentRichTextBox.SelectAll();
}
When you finish, test the program’s new features. One of the RichTextBox’s more remarkable fea-
tures is its ability to paste different kinds of items from the clipboard. For example, copy a picture to
the clipboard and then use the program to paste it into the RichTextBox.
Please select Lesson 7 on the DVD to view the video that accompanies this lesson.
EXERCISES
1. (SimpleEdit) Copy the SimpleEdit program you built for the Try It and add simple code to
handle the File menu’s New, Open, Save, and Exit commands. For the New command, simply
clear the
RichTextBox. For the Open and Save commands, just load and save the file “Test.
rtf.” (The program will create the file the first time you save. If you try to open the file before it
exists, the program will crash so don’t use Open before you use Save.) Lesson 8 explains how
to use file open and save dialogs to let the user pick the file that should be opened or saved.
2. (SimpleEdit) Copy the SimpleEdit program you built for Exercise 1 and add code to handle
the Format menu’s commands (except for the Font command, which is covered in Lesson 8).
Remove the placeholder
MessageBox.Show commands. Figure 7-9 shows the program with
its Format menu and Align submenu expanded.
596906c07.indd 86 4/7/10 12:32:07 PM