Color a specific word in a long text in c# -
i have long text contains key word "passed", "failed". wondering how color key work not entire line.
private void txt_textchanged(object sender, eventargs e) { this.checkkeyword("passed", color.purple, 0); this.checkkeyword("failed", color.green, 0); } private void checkkeyword(string word, color color, int startindex) { if (this.txt.text.contains(word)) { int index = -1; int selectstart = this.rchtxt.selectionstart; while ((index = this.txt.text.indexof(word, (index + 1))) != -1) { this.txt.select((index + startindex), word.length); this.txt.selectioncolor = color; this.txt.select(selectstart, 0); this.txt.selectioncolor = color.black; } } }
Comments
Post a Comment