AllTheTimeWorld.com

csharp richtextChange color of selected text.

Change color of selected text.

Uses the Color Dialog to select color of selected text

Change color of selected text.

Uses the Color Dialog to select color of selected text

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.