Zebra Notes: Open, Save, Save As, and Format with a Rich Text Box
Learn C# (C sharp) in FREE step-by-step lessons.
Module 19: Zebra Notes: Open, Save, Save As, and Format with a Rich Text Box
In this lesson we will create an application similar to notepad, but we will use a RichTextBox
so that you can format the text to make it bold, italics, etc.
The file type that we will create is rtf.

Goals:
- Work with a Rich Text Box;
- Format Text; Save changes;
- Remind to Save;
- Use Context menus to copy, cut and paste.
Objectives:
- Use variables to track changes;
- Resize a Rich text box;
- Use a timer to show the current time;
- Work with an RTF file;
- Write code to create a context menu
- Implement Ask to Save.
Please study the material at each of the links below.
Microsoft Reference: The Rich Text Box Overview
Build the Form: Show all the controls and properties for this project- Declare variables to track changes: In order to remind the user to save, we use a Boolean variable changed
- Resize: Rich text box fills the form: Richtext box fills the lower part of the form: between the toolstrip and the statusbar
- Display the date and time on timer tick: Timer event: toolStripStatusDateTime.Text = System.DateTime.Now.ToString();
- Save the file as rtf: Code for function to save the contents of the richtext box to file
- Do you want to save?: If there have been changes warn user when they select New, Open, or exit program.
- Remind to save before closing: Code to cancel closing the form if user wants to save first.
- Remind to save before Opening new file: Code to open a new file and load it asks about saving first
- Remind to save when selecting New: On selecting new, first ask about saving (if changes), then clear text and filename
- Change font of selected text: Uses the Font Dialog to select font
- Change color of selected text: Uses the Color Dialog to select color of selected text
- Using clipboard to copy, cut and paste: Code implements copy, cut and paste using the clipboard
Using a context menu to copy, cut and paste: A context menu is a pop-up menu that appears on right click- Finishing touches: Finishing touches include adding icon, about box, and removing unused menu items
Glossary for richtext lessonFull Glossary