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
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
d gPosted Jun 11, 2006, 11:51 AM
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 = "... "