Exemplo n.º 1
0
        private void SearchAndReplace()
        {
            int count = 1;

            // To prevent flickering
            richEditControl1.Document.BeginUpdate();

            // Get first search result and start iterating
            ISearchResult searchResult = richEditControl1.Document.StartSearch(searchString, SearchOptions.CaseSensitive, SearchDirection.Forward, richEditControl1.Document.Range);

            while (searchResult.FindNext())
            {
                searchResult.Replace(String.Empty);
                DocumentRange insertRange = richEditControl1.Document.InsertText(searchResult.CurrentResult.Start, replaceString);
                richEditControl1.Document.InsertRtfText(insertRange.End, replaceRtfPart.Replace("$number$", count.ToString()));
                count++;
            }

            richEditControl1.Document.EndUpdate();
        }