How do I find the viewable area of a WPF RichTextBox?
Posted
by shoe
on Stack Overflow
See other posts from Stack Overflow
or by shoe
Published on 2009-08-04T17:00:48Z
Indexed on
2010/05/15
22:02 UTC
Read the original article
Hit count: 129
I'm working on an app where I have a bunch of text in a RichTextBox. I'm jumping to various positions within the text, (hopping to an arbitrary paragraph for example) which seems to work by send the caret to that position but I can't seem to control where in the viewable area the caret ends up.
Sometimes the caret ends up at the top of the RichTextBox and sometimes at the bottom. This would be fine if I was only interested in the line that the caret is on but I'm interested in the entire paragraph.Ideally I'd like to get the caret in the middle of the RichTextBox everytime. Unless the Paragraph is longer than the viewable area.
My question. Is there a way to determine the viewable area of a RichTextBox and so do a calculation on how to position the caret properly? If I had that value I can then decided whether to put the caret in the middle (and know where the middle is) or at the top. Thanks for you help.
© Stack Overflow or respective owner