internal static void ClearHighlightsResults(Form1 form) { XtraTabControl pagesTabControl = form.pagesTabControl; if (form.IsOpening) { return; } RichTextBox tempRichTextBox = new RichTextBox(); //Temporary RichTextBox to avoid too much undo/redo into buffer try { foreach (XtraTabPage tabPage in pagesTabControl.TabPages) { CustomRichTextBox textBox = ProgramUtil.GetPageTextBox(tabPage); textBox.SuspendPainting(); tempRichTextBox.Rtf = textBox.Rtf; tempRichTextBox.SelectAll(); tempRichTextBox.Font = new Font(textBox.Font, FontStyle.Regular); tempRichTextBox.SelectionBackColor = tempRichTextBox.BackColor; RichTextBoxUtil.ReplaceRTFContent(textBox, tempRichTextBox); textBox.ResumePainting(); } } finally { tempRichTextBox.Dispose(); } TextManager.RefreshUndoRedoExternal(form); }
internal static void ClearHighlightsResults(CustomRichTextBox pageTextBox) { RichTextBox tempRichTextBox = new RichTextBox(); //Temporary RichTextBox to avoid too much undo/redo into buffer try { pageTextBox.SuspendPainting(); tempRichTextBox.Rtf = pageTextBox.Rtf; tempRichTextBox.SelectAll(); tempRichTextBox.Font = new Font(pageTextBox.Font, FontStyle.Regular); tempRichTextBox.SelectionBackColor = tempRichTextBox.BackColor; RichTextBoxUtil.ReplaceRTFContent(pageTextBox, tempRichTextBox); pageTextBox.ResumePainting(); } finally { tempRichTextBox.Dispose(); } }
internal static int SearchCountOccurences(String text, String stringToSearch, Form1 form = null, CustomRichTextBox textBox = null, bool forceDisableHighlight = false, bool useRegularExpressions = false) { int counter = 0; bool highlights = false; if (!forceDisableHighlight) { highlights = ConfigUtil.GetBoolParameter("SearchHighlightsResults"); } RichTextBox tempRichTextBox = new RichTextBox(); //Temporary RichTextBox to avoid too much undo/redo into buffer try { if (textBox != null) //Research inside a textbox (usually the pageTextBox) { tempRichTextBox.Rtf = textBox.Rtf; tempRichTextBox.SelectAll(); tempRichTextBox.SelectionBackColor = textBox.BackColor; int positionSearchedText; int selectionLength; SearchReplaceUtil.FindStringPositionAndLength(text, stringToSearch, SearchReplaceUtil.SearchType.First, useRegularExpressions, tempRichTextBox, out positionSearchedText, out selectionLength); while (positionSearchedText != -1) { tempRichTextBox.Select(positionSearchedText, selectionLength); if (highlights) { tempRichTextBox.SelectionBackColor = (textBox.BackColor == Color.Yellow) ? Color.Red : Color.Yellow; } SearchReplaceUtil.FindStringPositionAndLength(text, stringToSearch, SearchReplaceUtil.SearchType.Next, useRegularExpressions, tempRichTextBox, out positionSearchedText, out selectionLength); counter++; } } else //Search inside a string { int i = 0; while ((i = text.IndexOf(stringToSearch, i)) != -1) { i += stringToSearch.Length; counter++; } } if (textBox != null && highlights) { textBox.IsHighlighting = true; RichTextBoxUtil.ReplaceRTFContent(textBox, tempRichTextBox); TextManager.RefreshUndoRedoExternal(form); } } finally { tempRichTextBox.Dispose(); } return(counter); }