Zebra0.com

csharp richtext

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.

End of lesson, Next lesson: That is the last C# lesson in this course.