public void Execute()
            {
                Document doc = this.control.Document;

                foreach (string word in str)
                {
                    ISearchResult result = control.Document.StartSearch(word, options, direction, doc.Range);
                    while (result.FindNext())
                    {
                        CharacterProperties charProperties = doc.BeginUpdateCharacters(result.CurrentResult);
                        charProperties.ForeColor = Color.IndianRed;
                        doc.EndUpdateCharacters(charProperties);
                    }
                }
                // your code here
            }
 private void SearchButton_Click(object sender, EventArgs e) //search a word
 {
     try
     {
         ISearchResult searchResult = MainRichTextBox.Document.StartSearch(SearchBox.Text);
         while (searchResult.FindNext())
         {
             CharacterProperties cp = MainRichTextBox.Document.BeginUpdateCharacters(searchResult.CurrentResult);
             //cp.Bold = true;
             //cp.ForeColor = System.Drawing.Color.Blue;
             cp.BackColor = Color.YellowGreen;
             //cp.Underline = UnderlineType.ThickSingle;
             MainRichTextBox.Document.EndUpdateCharacters(cp);
         }
     }
     catch { }
 }
Beispiel #3
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();
        }