Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
    Overview
   [Expand]Getting Started
   [Expand]Fundamentals
   [Collapse]Concepts
     Text Formatting
     Import and Export
     Mail Merge
     Restrictions and Protection
     Line Numbering
     Table of Contents
     Check Spelling
     AutoCorrect
     Printing
     Syntax Highlighting
     Traversing the Document
   [Expand]Visual Elements
   [Expand]Examples
   [Expand]Member Tables
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Text Formatting

RichEditControl provides two ways to format document text.

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

  • Document Styles
    Styles can change multiple attributes at the same time. Styles created in code are automatically available to end-users. If you change the style settings, all linked document fragments will be updated automatically.

Both approaches described above are available in API and in the User Interface.

Expanded Direct Formatting

To set the default character and paragraph formatting for a loaded or newly created document, use the following properties.

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

To modify the document title as shown in the image below, use both character and paragraph formatting.

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.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T456449.

Format Paragraphs

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

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.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T456449.

Expanded Document Styles

RichEditControl supports the use of two types of document styles: paragraph and character. The character style can be used if only the character options need to be modified. To change both character (a font type, size, color, etc.) and paragraph (alignment, spacing before and after, etc.) attributes as in the current example, use the paragraph style.
The image below demonstrates chapter titles modified using the paragraph style.


By default, RichEditControl doesn't have any predefined document styles. To create a new document style, use the members from the table below.

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.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T456449.


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

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

Linked Styles

To format the document annotation, use a linked style. 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. With the style applied to the DocumentRange instance, only character formatting is used.

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

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T456449.

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.

To learn how to provide the application with the Ribbon Command UI, refer to the How to: Create a Simple Word Processor with a Ribbon UI topic.

Additionally, the Rich Text Editor application is provided with the following dialogs, which allow end-users to set the character and paragraph formatting options and manage the document styles.

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
DocumentCapabilitiesOptions.CharacterFormatting
DocumentCapabilitiesOptions.ParagraphFormatting
Allows you to restrict end-users from direct formatting.
DocumentCapabilitiesOptions.CharacterStyle
DocumentCapabilitiesOptions.ParagraphStyle
Allows you to disable using document styles at runtime.

Expanded See Also

How would you rate this topic?​​​​​​​