/// <summary> /// Called when the user presses the replace all button /// </summary> /// <param name="arg"></param> void OnReplaceAllButtonClick(NEventArgs arg) { // init find settings NFindTextSettings settings = new NFindTextSettings(); settings.FindWhat = m_FindTextBox.Text; settings.SearchDirection = ENSearchDirection.Forward; // find all occurances NTextSearcher searcher = new NTextSearcher(m_DrawingView, settings); searcher.ActivateEditor = false; NShapeTextSearchState state; while (searcher.FindNext(out state)) { NSelection selection = state.Shape.GetTextSelection(); // replace NRangeI selectedRange = selection.SelectedRange; selection.InsertText(m_ReplaceTextBox.Text); if (m_ReplaceTextBox.Text.Length > 0) { selection.SelectRange(new NRangeI(selectedRange.Begin, selectedRange.Begin + m_ReplaceTextBox.Text.Length - 1)); selection.SetHighlightFillToSelectedInlines(new NColorFill(ENNamedColor.LimeGreen)); } } }
/// <summary> /// Called when the user presses the find all button /// </summary> /// <param name="arg"></param> void OnFindAllButtonClick(NEventArgs arg) { // init find settings NFindTextSettings settings = new NFindTextSettings(); settings.FindWhat = m_FindTextBox.Text; settings.SearchDirection = ENSearchDirection.Forward; // loop through all occurances NRangeI textRange = NRangeI.Zero; NTextSearcher searcher = new NTextSearcher(m_DrawingView, settings); searcher.ActivateEditor = false; NShapeTextSearchState state; while (searcher.FindNext(out state)) { state.Shape.GetTextSelection().SetHighlightFillToSelectedInlines(new NColorFill(ENNamedColor.Red)); } }