How to select all text in RichTextBox by code?

3 posts, 0 answers
  1. Michael Hilgers
    Michael Hilgers avatar
    76 posts
    Member since:
    Apr 2010

    Posted 20 Jun 2012 Link to this post

    Hello everyone,

    i need to know how i can select the whole text in a RichTextBox by code-behind.

    My target is to apply a default font size and font family to the content of the RichTextBox, but ChangeFontSize() and ChangeFontFamily() only applys to selected text and has no effect if there is no selected text. And i can't find any other possibility to set the size and family.

    Or does anyone have another solution for applying the styles to the content of the RichTextBox ?

    Kind Regards,
    Michael
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 20 Jun 2012 Link to this post

    Hi Michael,

    Thank you for writing.

    Here is the coded needed to change the font:
    private void ChangeFont()
    {
        radRichTextBox1.Document.Selection.SelectAll();
        radRichTextBox1.ChangeFontFamily("Comic Sans MS");
        radRichTextBox1.ChangeFontSize(22);
        radRichTextBox1.Document.Selection.Clear();
    }

    I hope this helps.
     
    Regards,
    Stefan
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Michael Hilgers
    Michael Hilgers avatar
    76 posts
    Member since:
    Apr 2010

    Posted 20 Jun 2012 Link to this post

    Hello Stefan,

    thx, it looks like i missed the Selection property in the Document .... ;) Sorry!

    Regards,
    Michael
Back to Top