Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get displayed text from RichTextBox?

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

like image 711
Ilya Blokh Avatar asked May 01 '10 15:05

Ilya Blokh


People also ask

Can RichTextBox display HTML?

Presents code to display bindable HTML text in a WPF RichTextBox or a WebBrowser.

What is difference between RichTextBox and TextBox?

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.


1 Answers

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.

like image 174
Hans Passant Avatar answered Oct 14 '22 03:10

Hans Passant