Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Specify Default Document Formatting

  • 2 minutes to read

You can use one of the following approaches to specify default document formatting.

#Set Default Formatting to the RichEditControl

The static RichEditControlCompatibility.DefaultFontSize and RichEditControlCompatibility.DefaultFontName properties set the default font settings for all RichEditControl instances in the application. Specify these properties before initialization of all controls, in the Main method, as illustrated in the following code.

View Example

static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    DevExpress.XtraRichEdit.RichEditControlCompatibility.DefaultFontSize = 8;
    DevExpress.XtraRichEdit.RichEditControlCompatibility.DefaultFontName = "Tahoma";
    Application.Run(new Form1());
}

#Set Default Formatting to the Specific Document

For the document loaded in the RichEditControl, you can specify default formatting characteristics individually using the Document.DefaultCharacterProperties and Document.DefaultParagraphProperties settings. These settings override the RichEditControlCompatibility settings.

View Example

Private Sub RichEditControl1_EmptyDocumentCreated(ByVal sender As Object, ByVal e As EventArgs)
    richEditControl1.Document.DefaultCharacterProperties.ForeColor = Color.Red
    richEditControl1.Document.DefaultParagraphProperties.Alignment = DevExpress.XtraRichEdit.API.Native.ParagraphAlignment.Center
    richEditControl1.Document.AppendText("Document created at " & Date.Now.ToLongTimeString())
End Sub

Tip

To copy default document formatting from one document to another, use the Assign method. The code snippet below copies default document formatting characteristics from the document loaded in the richEditControl2 control to the document contained in the richEditControl1 :

richEditControl1.Document.DefaultCharacterProperties.Assign(richEditControl2.Document.DefaultCharacterProperties);
richEditControl1.Document.DefaultParagraphProperties.Assign(richEditControl2.Document.DefaultParagraphProperties);
See Also