开发者

WPF RichTextBox GetCharacterRect

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

T开发者_如何转开发he content from Microsoft here shows the same. Is anybody aware of an alternative to measure the character rect ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜