In my RichtextBox
, if I have written as below.
This is my pen,
his pen is beautiful.
Now I search word "is" then output would be as below.
All "is" should be highlighted.
Enter a search string in the search control. I entered very (Figure B). Click Reading Highlight and choose Highlight All and Word will highlight all instances of very.
If you want to highlight a whole line of text, move your cursor to the start of the line, hold the Shift key, and then press the Down arrow . You may also use the shortcut key combination Shift + End . If you want to highlight all text (the entire page), press the shortcut key Ctrl + A .
What about:
static class Utility {
public static void HighlightText(this RichTextBox myRtb, string word, Color color) {
if (word == string.Empty)
return;
int s_start = myRtb.SelectionStart, startIndex = 0, index;
while((index = myRtb.Text.IndexOf(word, startIndex)) != -1) {
myRtb.Select(index, word.Length);
myRtb.SelectionColor = color;
startIndex = index + word.Length;
}
myRtb.SelectionStart = s_start;
myRtb.SelectionLength = 0;
myRtb.SelectionColor = Color.Black;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With