5

I am trying to get the character rect for all characters typed inside a richtextbox. Starting from the MyRichTextBox.Document.ContentStart textpointer, I advance every character using the following code

currentPointer = currentPointer.GetNextInsertionPosition(LogicalDirection.Forward)

And retrieve the "character" rect using the following code

currentPointer.GetCharacterRect(LogicalDirection.Forward)

But it looks like, for any textpointer returned from the piece of code above, the width of the rect is always 0. Now I am able to calculate the character rect based on the area between previous character rect and current character rect, but this causes a problem when a word wrap occurs.

Is there any way I can get a non-zero width from the GetCharacterRect() function of the rich text box ?

EDIT

The content from Microsoft here shows the same. Is anybody aware of an alternative to measure the character rect ?

Manoj
  • 5,011
  • 12
  • 52
  • 76

1 Answers1

2

GetCharacterRect just returns a rectangle representing the leading edge of the character in question (i.e., a zero-width, but accurate height and position) - not a "wrapper rectangle"...although if that's what you are after, you could grab the leading edge of two consecutive characters and do the math.

JerKimball
  • 16,584
  • 3
  • 43
  • 55