private void ExecuteContextSearch() { if (rbContextSearchText.Checked) { SearchProvider.Search(txtContextSearch.Text, SearchType.PlainText, !chkBoxContextSearchCaseSensitive.Checked); } else if (rbContextSearchRegexp.Checked) { SearchProvider.Search(txtContextSearch.Text, SearchType.Regex, !chkBoxContextSearchCaseSensitive.Checked); } else if (rbContextSearchXpath.Checked) { SearchProvider.Search(txtContextSearch.Text, SearchType.xPath, true); } toolStripStatusLabelContextSearchResults.Text = string.Format("{0:n0} item{1} found", (SearchProvider.Matched == 0 ? "No" : SearchProvider.Matched.ToString()), SearchProvider.Matched == 1 ? "" : "s"); rtbFileContent.SelectionStart = 0; rtbFileContent.SelectionLength = 0; return; string txt = rtbFileContent.Text; string searchAt = txtContextSearch.Text; RegexOptions reOpt = RegexOptions.Multiline;//& */RegexOptions.IgnoreCase; if (rbContextSearchText.Checked) { if (string.IsNullOrEmpty(searchAt)) { return; } searchAt = Regex.Replace( searchAt, @"([\(\)\.\[\]\}\\\$\^\|\+|\*\?])", @"\$1"); } if (!chkBoxContextSearchCaseSensitive.Checked) { reOpt |= RegexOptions.IgnoreCase; } MatchCollection mc = Regex.Matches(txt, searchAt, reOpt); for (int i = 0; i < mc.Count; i++) { rtbFileContent.SelectionStart = mc[i].Index; rtbFileContent.SelectionLength = mc[i].Length; //rtbFileContent.SelectionBackColor = Color.GreenYellow; int blueDelta; // max value of blue component int blueMin = 10; int blueMax = 220; blueDelta = blueMax; if (mc[i].Length < 40) // 40 - chars most light yellow { blueDelta = blueMin + (blueMax - blueMin) / 40 * mc[i].Length; } //blue = 32; rtbFileContent.SelectionBackColor = Color.FromArgb(250, 250, blueDelta); } toolStripStatusLabelContextSearchResults.Text = string.Format("{0:n0} item{1} found ", SearchProvider.Matched, SearchProvider.Matched == 1 ? "" : "s"); rtbFileContent.SelectionStart = 0; rtbFileContent.SelectionLength = 0; }