tags:

views:

344

answers:

0

Hi,

I have a System.Control.RichTextBox (not System.Form.RichTextBox), and I would like look for a specific word, and apply certain decoration on the found phrase. So far, I got this, but it's not working properly. I am looking for a list of words, but the TextPointer is not pointing to the right location.Therefore, all my ranges are incorrect. Any idea to do it better?

thanks,

I do run this in a loop of my words:

startPos =  new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd).Text.IndexOf(word);
leftPtr = textPointer.GetPositionAtOffset(startPos+1, LogicalDirection.Forward);Rect leftSelectedRect=  textPointer.GetCharacterRect(LogicalDirection.Forward);
rightPtr = textPointer.GetPositionAtOffset((startPos+Word.Length), LogicalDirection.Backward);

Rect rightSelectedRect = textPointer.GetCharacterRect(LogicalDirection.Forward);
TextRange myRange = new TextRange(leftPtr, rightPtr);