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

2 posts, 1 answers
  1. Greg
    Greg avatar
    32 posts
    Member since:
    Sep 2012

    Posted 29 Sep 2012 Link to this post


    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.
    // Clear the previous selection.
    // Select line text.
    var currentLine = richFolderList.Document.Selection.GetSelectedText();
  2. Answer
    Petya avatar
    973 posts

    Posted 02 Oct 2012 Link to this post

    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.
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft R3 2016 release webinar banner
Back to Top