From 2480f5593aa029fe459dbd067e18b36041facf2c Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 31 May 2015 22:44:20 -0700 Subject: [PATCH] Add text highlighting method --- pk3DS/Util.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pk3DS/Util.cs b/pk3DS/Util.cs index 1aee7a5..fc28851 100644 --- a/pk3DS/Util.cs +++ b/pk3DS/Util.cs @@ -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; + } } }