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

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

    Posted 29 Sep 2012 Link to this post

    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();
    
    
  2. Answer
    Petya
    Admin
    Petya avatar
    975 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.
     
    Regards,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top