Highlight specific string in Richtextbox control

This function highlight particular string by user defined color
call this function like in your code .
richTextBox1.Text = "This is Sample Application";
richTextBox1= HighLightColor(7,8,Color.Red,richTextBox1);

for Ex. StartIndex=7,EndIndexLength=8,strCol =Color.Red and pass richtextbox1

public RichTextBox HighLightColor(int StartIndex, int EndIndexLength, Color strCol, RichTextBox rtbox)
rtbox.Select(StartIndex, EndIndexLength);
rtbox.SelectionColor = strCol;
return rtbox;


This gives output "Sample" string is highlighted by Red color;


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: