Skip to main content
A newer version of this page is available. .

How to: Specify Default Document Formatting

Use the Document.DefaultCharacterProperties and Document.DefaultParagraphProperties properties available via the RichEditDocumentServer.Document.DefaultCharacterProperties and RichEditDocumentServer.Document.DefaultParagraphProperties notations.

Changing default setting will change those portions of the text that have not been formatted explicitly, but leave already formatted text as it is. For example, default font is Arial 12. If I set a selection to Times New Roman 14 and then set the default setting to Arial 10, the text formatted with Times New Roman 14 remains unchanged.

The following code snippet illustrates how to specify default document formatting when a new empty document is created. A new empty document can be created by calling the RichEditDocumentServer.CreateNewDocument method.


private void server_EmptyDocumentCreated(object sender, EventArgs e) {
    server.Document.DefaultCharacterProperties.ForeColor = Color.Red;
    server.Document.DefaultParagraphProperties.Alignment = ParagraphAlignment.Center;
    server.Document.AppendText("Document created at " + DateTime.Now.ToLongTimeString()); }