使用FindText方法查找字符.
记录匹配项的StartPosition.通过MatchSelection()方法选定.
部分代码
string textToFind = findDialog.SearchText; ITextRange searchRange = redit.Document.GetRange(0, 0); int match_count = 0;int firstPosition = 0; while (searchRange.FindText(textToFind, TextConstants.MaxUnitCount, FindOptions.None) > 0) { searchRange.CharacterFormat.BackgroundColor = Colors.DeepPink; if (match_count == 0) { firstPosition=searchRange.StartPosition; //searchRange.ScrollIntoView(PointOptions.AllowOffClient); //searchRange.MoveEnd(TextRangeUnit.Character,0); } match_count += 1; } Debug.WriteLine(firstPosition); searchRange = redit.Document.GetRange(firstPosition, firstPosition+textToFind.Length); searchRange.MatchSelection();