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

Changing whole document font/size

1 Answer 145 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 12 Dec 2014, 08:18 PM
I've got a RichTextEditor that I'm filling with the output from an HtmlFormatProvider.Import

After I've imported, I'd like to change the font and font size for the entire document.  Is there a way to do this?

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 17 Dec 2014, 07:41 AM
Hello Michael,

Thank you for contacting Telerik Support.

Please refer to this help topic where you can find information regarding the Selection of text in our RichTextEditor control. Below is a code snippet with a sample implementation of selecting the available text in a RadDocument element and applying FontFamily and FontSize settings:
public Form1()
{
    InitializeComponent();
 
    //Load html document
    using (Stream stream = new MemoryStream(File.ReadAllBytes(@"..\..\..\sample.html")))
    {
        HtmlFormatProvider provider = new HtmlFormatProvider();
        this.radRichTextEditor1.Document = provider.Import(stream);
    }
 
    //Select the entire text
    DocumentPosition startPosition = this.radRichTextEditor1.Document.CaretPosition;
    DocumentPosition endPosition = new DocumentPosition(startPosition);
    startPosition.MoveToStartOfDocumentElement(this.radRichTextEditor1.Document);
    endPosition.MoveToEndOfDocumentElement(this.radRichTextEditor1.Document);
    this.radRichTextEditor1.Document.Selection.Clear();
    this.radRichTextEditor1.Document.Selection.AddSelectionStart(startPosition);
    this.radRichTextEditor1.Document.Selection.AddSelectionEnd(endPosition);
 
    //Change font family and size
    this.radRichTextEditor1.RichTextBoxElement.ChangeFontFamily(new Telerik.WinControls.RichTextEditor.UI.FontFamily("Verdana"));
    this.radRichTextEditor1.RichTextBoxElement.ChangeFontSize(Unit.PointToDip(16));
}

I would also suggest that you get acquainted with our demo application and RichTextEditor example. The source code of the project is usually located at: C:\Program Files (x86)\Telerik\UI for WinForms Q3 2014\Examples\RichTextEditor.

I hope that this information is useful. Should you have further question do not hesitate to write back.

Regards,
Hristo
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
RichTextEditor
Asked by
Michael
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or