Add text highlighting method

This commit is contained in:
Kurt
2015-05-31 22:44:20 -07:00
parent d302799b7f
commit 2480f5593a

View File

@@ -620,5 +620,24 @@ internal static byte[] StringToByteArray(string hex)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}
internal static int highlightText(RichTextBox RTB, string word, Color hlColor)
{
int ctr = 0;
int s_start = RTB.SelectionStart, startIndex = 0, index;
while ((index = RTB.Text.IndexOf(word, startIndex, StringComparison.Ordinal)) != -1)
{
RTB.Select(index, word.Length);
RTB.SelectionColor = hlColor;
startIndex = index + word.Length;
ctr++;
}
RTB.SelectionStart = s_start;
RTB.SelectionLength = 0;
RTB.SelectionColor = Color.Black;
return ctr;
}
}
}