Want to highlight a piece of string in Rich Text Box
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.
d g18 pointsPosted Jun 11, 2006, 7:51 AM EDT
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 = "... "