Search This Blog

Thursday, September 25, 2014

RichTextBox control insert color text

C# > RichTextBox Control > SelectionColor 


Gets or sets the text color of the current text selection or insertion point.

Example

private void AppendText(RichTextBox rtb, string text, Color color)
{
       rtb.SelectionStart = rtb.TextLength;
       rtb.SelectionLength = 0;

       rtb.SelectionColor = color;
       rtb.AppendText(text);
       rtb.SelectionColor = rtb.ForeColor;
}

AppendText(richTextBox1, "Blue", Color.Blue);

AppendText(richTextBox1, "Red", Color.Red);