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

How to select all text in RichTextBox by code?

2 Answers 1479 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Michael Hilgers
Top achievements
Rank 1
Michael Hilgers asked on 20 Jun 2012, 11:56 AM
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 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 20 Jun 2012, 12:50 PM
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 >>
0
Michael Hilgers
Top achievements
Rank 1
answered on 20 Jun 2012, 12:54 PM
Hello Stefan,

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

Regards,
Michael
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Michael Hilgers
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Michael Hilgers
Top achievements
Rank 1
Share this question
or