How to get displayed text in RichTextBox? I mean if RichTextBox is scrolled to the end, I'd like to receive only those lines, which are visible for me.
P.S.It'll be enough to get fisrt displayed string
Presents code to display bindable HTML text in a WPF RichTextBox or a WebBrowser.
The RichTextBox is similar to the TextBox, but it has additional formatting capabilities. Whereas the TextBox control allows the Font property to be set for the entire control, the RichTextBox allows you to set the Font, as well as other formatting properties, for selections within the text displayed in the control.
You want to use RichTextBox.GetCharIndexFromPosition(). To get the index of the first visible character, pass new Point(0, 0), the upper left corner of the RTB client area. To get the index of the last visible character, pass new Point(rtb.ClientSize.Width, rtb.ClientSize.Height). RichTextBox.Text.Substring() then gets you all visible text.
If necessary, you can use RichTextBox.GetLineFromCharIndex() to translate the character indexes to line numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With