[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
    Supported Formats
   [Expand]Getting Started
   [Expand]RichEditControl Document
   [Expand]Fields
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Printing
    Hyphenation
    AutoCorrect
    Track Changes
    Mail Merge
    Restrictions and Protection
   [Expand]Visual Elements
    Services
    Events
    Commands
    HTML Tag Support
   [Expand]Examples
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Text Formatting

RichEditControl provides two ways to format document text in code and via User Interface

  • Direct Formatting

    Allows you to change individual formatting attributes for a given range.

  • Document Styles

    Allow you to change multiple attributes at the same time and apply them to different document fragments. Styles created in code are automatically available to end users. If you change the style settings, all linked document fragments will be updated automatically.

Expanded Default Formatting

Use the following properties to set the default character and paragraph formatting for a loaded or newly created document.

The code snippet below illustrates how to apply default formatting to a loaded document.

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.

Important

Starting with v19.2, the RichEditControl uses document themes to retrieve default font information. As such, the RichEditControlCompatibility.DefaultFontName property does no longer affect the default document font. Set the RichEditControlCompatibility.UseThemeFonts property to false to restore previous behavior and use the DefaultFontName property.

Expanded Direct Formatting

Use both character and paragraph formatting for a specific document range, for instance, for the document title as shown below.

Format Characters

The following members allow you to change character formatting for a given range.

Member Description
SubDocument.BeginUpdateCharacters Initiates the update session and provides access to CharacterProperties for the specified range.
CharacterProperties Holds the character formatting options.
SubDocument.EndUpdateCharacters Finalizes the character formatting update.

The code sample below uses this API to modify the text color and the font type.

Theme Fonts

The RichEditControl supports theme fonts. A document theme contains two sets of fonts (Headings and Body). Each set includes font names for different languages. You can use the following properties to specify these fonts for a specific document range:

Property Description
CharacterPropertiesBase.ThemeFontAscii Specifies the theme font used to format Unicode (U+0000–U+007F) characters. If the ThemeFontAscii is not specified, CharacterPropertiesBase.FontNameAscii property determines the theme font.
CharacterPropertiesBase.ThemeFontEastAsia Specifies the theme font used to format East Asian Unicode characters. If the ThemeFontEastAsia is not specified, the CharacterPropertiesBase.FontNameEastAsia property determines the theme font.
CharacterPropertiesBase.ThemeFontHighAnsi Specifies the theme font used to format High ANSI characters. If the ThemeFontHighAnsi is not specified, the CharacterPropertiesBase.FontNameHighAnsi property determines the theme font.
CharacterPropertiesBase.ThemeFontComplexScript Specifies the name of the Complex Script theme font. If the ThemeFontComplexScript is not specified, the CharacterPropertiesBase.FontNameComplexScript property determines the theme font.

You can use the Document.Theme property to specify Body and Heading fonts used in the document for Latin, Complex Script and East Asian languages. Create a new DocumentTheme (see DocumentTheme) object and pass it as the Theme property value, as shown in the code sample below:

Format Paragraphs

Use the following API to change the title's alignment, left indent or any other paragraph option.

Member Description
SubDocument.BeginUpdateParagraphs Initiates the update session and provides access to the ParagraphProperties for the specified range.
ParagraphProperties Specifies the paragraph formatting properties.
SubDocument.EndUpdateParagraphs Finalizes the character formatting update.

Expanded Document Styles

RichEditControl supports paragraph and character styles. The character style can be used if only the character options need to be modified. Use the paragraph style to change both character (a font type, size, color, etc.) and paragraph (alignment, spacing before and after, etc.) attributes as in the current example.

The image below demonstrates chapter titles modified using the paragraph style.

RichEditControl doesn't have any predefined document styles. Use the members from the table below to create a new document style.

Member

Description

SubDocument.BeginUpdate

Opens the document for editing.

Document.CharacterStyles

Document.ParagraphStyles

Provides access to the CharacterStyleCollection

Provides access to the ParagraphStyleCollection.

CharacterStyleCollection.CreateNew

ParagraphStyleCollection.CreateNew

Creates a new CharacterStyle object.

Creates a new ParagraphStyle object.

CharacterStyle.Parent

ParagraphStyle.Parent

Specifies the base style for the created instance.

CharacterStyle.LinkedStyle

ParagraphStyle.LinkedStyle

Allows you to synchronize the character and paragraph styles to create a linked style.

CharacterStyleCollection.Add

ParagraphStyleCollection.Add

Adds the created style to the collection.

Paragraph.Style

Sets the style to the given paragraph.

CharacterProperties.Style

Specifies the style to the given character range.

SubDocument.EndUpdate

Finalizes style creation.

The code sample below demonstrates how to create a new paragraph style and apply it to every chapter.

If the loaded document already has document styles, they are automatically added to the document's StyleCollection and you can use them as shown in the code snippet below.

Tip

Load an empty document created in Microsoft® Word® using the Document.LoadDocument method in the RichEditControl.EmptyDocumentCreated event handler to fill the collection of a newly created document with the predefined styles.

Linked Styles

Use a linked style to format the document annotation. A linked style carries both character and paragraph formatting rules, but applies them according to the target object. If the style is applied to the Paragraph instance, both formatting options will be applied. Only character formatting is used if the style is applied to the DocumentRange instance.

The code sample below demonstrates how to synchronize a paragraph and character style to create a linked style.

The image below illustrates the result of the code execution.

Expanded Text Formatting In the User Interface

End users can change the required format settings using the Font and Paragraph groups of the Home ribbon tab.

The Style Gallery allows end users to preview and apply the desired document style to the selected text fragment.

Refer to the How to: Create a Simple Word Processor with a Ribbon UI topic for an example on how to provide the application with the Ribbon Command UI.

The Rich Text Editor application ships with the following dialogs.

You can prevent end users from formatting the document. As a result, the corresponding ribbon buttons and the context menu items will be disabled or hidden.

The following members allow you to accomplish this task.

Member

Description

DXRichEditDocumentCapabilitiesOptions.CharacterFormatting

DXRichEditDocumentCapabilitiesOptions.ParagraphFormatting

Allows you to restrict end-users from direct formatting.

DXRichEditDocumentCapabilitiesOptions.CharacterStyle

DXRichEditDocumentCapabilitiesOptions.ParagraphStyle

Allows you to disable using document styles at runtime.

Is this topic helpful?​​​​​​​