How to get display text from RichTextBox?

How to get display text in RichTextBox? I mean, if the RichTextBox scrolls to the end, I would like to get only those lines that are visible to me.

PSIt will be enough to get the fisrt display string

+3
source share
4 answers

You must use RichTextBox.GetCharIndexFromPosition( point ).

To get the index of the first visible character, go through new Point(0, 0)(upper left corner of the RTB client area) as a parameter point.
To get the index of the last visible character, pass new Point(rtb.ClientSize.Width, rtb.ClientSize.Height)as a parameter point.

RichTextBox.Text.Substring() .

RichTextBox.GetLineFromCharIndex() .

+5

EM_GETFIRSTVISIBLELINE API SendMessage.

0

eggcafe:

" , .

richtextbox , TextHeight . .

, richtextbox.

, . "

http://www.eggheadcafe.com/community/aspnet/2/10073516/how-to-select-the-visible.aspx

0
source

Not elegant, but I think it works.

//Force selection 

richTextBox.SelectAll();

//Get the selected text

dataString = richTextBox.Selection.Text;

This, of course, will not work if you want to allow the user to select text, etc.

0
source

Source: https://habr.com/ru/post/1743637/


All Articles