Skip to content

Want to highlight a piece of string in Rich Text Box

Salman Iqbal

Asked May 25, 2006, 8:03 PM EDT1 answer
Share
LinkedInX
I want to highlight a specific peice of string with any color How can I do it in C# form based programming .Plz help me it is important & very urgent as well

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    you can use the prebuilt class as follows...

    richTextBox.Select(start_index, length_of_text);
    richTextBox.SelectionColor = Color.Red;  // or custom color, whatever

    If you are using a large richTextBox, then doing it this way is a terrible idea, its very slow (if you're highlighting things all over the place)... I have previously made a class that writes a .rtf file to disk and then loads it into the richTextBox... that method is magnitudes faster, but considerably more complicated (unless you use my class  ;) ). If you can manage to squeeze all of the rtf code into a string (or maybe use an array of strings), then you can also use richTextBox.Rtf = "... "
    0