This is a migrated thread and some comments may be shown as answers.

How to get all the text from a rich text box?

1 Answer 408 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 29 Sep 2012, 05:01 PM
Hello,

Is there a way to get all the text from a RichTextBox without having to select all the text first and then call GetSelectedText() on the document selection?


PS: Also, is it possible to get parts of text without having to select it first? For example, if I want to get the text on a line, i currently do this:
// Get line text range.
startPosition.MoveToCurrentLineStart();
endPosition.MoveToCurrentLineEnd();
 
// Clear the previous selection.
richFolderList.Document.Selection.Clear();
// Select line text.
richFolderList.Document.Selection.AddSelectionStart(startPosition);
richFolderList.Document.Selection.AddSelectionEnd(endPosition);
 
var currentLine = richFolderList.Document.Selection.GetSelectedText();

1 Answer, 1 is accepted

Sort by
0
Accepted
Petya
Telerik team
answered on 02 Oct 2012, 05:30 AM
Hello Greg,

To get the whole text of the document, you can use TxtFormatProvider as described in this article.

When it comes to your other question, the code you pasted is the correct one if you want to select the text on the current line. What you can do if you want to keep your current selection in the editor unchanged, is to create a new instance of the DocumentSelection class and operate with it, thus avoiding the need to change the visible UI selection. You can check this forum post to see how this can be done.

I hope this helps.
 
Regards,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Greg
Top achievements
Rank 1
Answers by
Petya
Telerik team
Share this question
or