Text Format in C# RichTextBox

RichTextBox.DeselectAll();

//Change color
RichTextBox.SelectionColor = Color.LimeGreen;

//Change font
RichTextBox.SelectionFont = new Font(RichTextBox.SelectionFont, FontStyle.Bold);

//Finally add text
RichTextBox.AppendText("Hello World" + Environment.NewLine);

Taken from this StackOverFlow Question-
http://stackoverflow.com/questions/4077582/format-text-in-rich-text-box

Advertisements

Formatted RichTextBox in C#

Color color = System.Drawing.Color.Green;
var lines= richTextBox.Lines;
int index = 0;
foreach (string line in lines)
{
   var start = richTextBox.GetFirstCharIndexFromLine(index);  //Get the 1st char index of a line.
   var length = lines[index].Length;
   richTextBox.Select(start, length); //Select from there to the end
   richTextBox.SelectionColor = color;
   index++;
}