Advertisement
KpoKec

Untitled

May 12th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1.         private void HighlightWord(RichTextBox rtb, string word, Color color) {
  2.             int startIndex = 0;
  3.             while (startIndex < rtb.TextLength) {
  4.                 int wordStartIndex = rtb.Find(word, startIndex, RichTextBoxFinds.None);
  5.                 if (wordStartIndex != -1) {
  6.                     rtb.SelectionStart  = wordStartIndex;
  7.                     rtb.SelectionLength = word.Length;
  8.                     rtb.SelectionColor  = color;
  9.                 }
  10.                 else
  11.                     break;
  12.  
  13.                 startIndex += wordStartIndex + word.Length;
  14.             }
  15.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement