Zebra0.com

csharp richtextZebra Notes: Open, Save, Save As, and Format with a Rich Text Box

Zebra Notes: Open, Save, Save As, and Format with a Rich Text Box

Continue with the Notes Application.

Next we will write the code to change the color of the selected text.

Add a button to the toolbar and name it toolStripColor. Download this image to use for the button:
If you wish, you can add a menu item for the color also.

Write the code shown below:

private void toolStripColor_Click(object sender, EventArgs e)
{
   SelectColor();
}

private void SelectColor()
{
   // Display the color dialog and change color of selected text.
   // If no text is selected this has no effect.
   Color selectionColor = richTextBox1.SelectionColor;
   colorDialog1.ShowDialog();
   richTextBox1.SelectionColor = colorDialog1.Color;
}

Click Save All at this point and run the program.

That's all! Congratulations on completing all of the lessons in csharp!