Skip to main content

XRRichText Class

A control that displays formatted text in a report.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v23.2.dll

NuGet Package: DevExpress.Reporting.Core

Declaration

public class XRRichText :
    XRRichTextBase,
    ISupportInitialize,
    IDisplayNamePropertyContainer

Remarks

To add the XRRichText control to a report, drag the XRRichText item from the DX:23.2: Report Controls Toolbox tab and drop the item onto the report’s bands.

Specify Formatted Text

You can add RTF or HTML content to the XRRichText control in one of the following ways:

Refer to the following topic for information on supported HTML tags: HTML Tag Support.

Copy From an External Resource

To add formatted text from an external resource, copy the text, double-click the control, and paste the text in the control’s in-place editor. The following example demonstrates an XRRichText control that contains formatted DevExpress Website Terms of Use text:

Load From a File

You can load content from RTF (.rtf, .docx, .txt) or HTML (.html or .htm ) files to the XRRichText control. Click the control’s smart tag and select Load File in the invoked actions list. See the following section for the list of limitations applicable for the loaded content: Limitations.

Select a file in the invoked Open dialog. After the file’s content is loaded, use the Formatting Toolbar and the control’s in-place editor to edit the content.

Load From a Data Source

You can bind the XRRichText control’s Rtf (Html) property to a data source field that contains RTF (HTML) content.

Click the control’s smart tag, expand the Rtf (Html) Expression drop-down list, and select the field to which you want to bind the control.

rich-text-rtf-expression

You can also use the Field List to bind the Rtf property. Right-click a field in the Field List, drop the field onto the report, and choose the RichText item in the invoked menu. This creates the XRRichText control whose Rtf property is bound to the selected field.

report-control-rich-text-1

Use expressions to specify a string that uses data from several data fields or to apply additional formatting to data. Click the Rtf (Html) Expression option’s ellipsis button and use the invoked Expression Editor to specify expressions.

rich-text-expression-editor

Note

When you use expression bindings to supply content for the XRRichText control, the control applies style settings defined at the level of the supplied content. If you then use the control’s properties to change the content style, the changes have no effect. If you need to edit the supplied content, use the RichEditDocumentServer component. Refer to the example that shows how to change the font of the content loaded from a data source.

XLS(X) Export Limitations

Only the following content of the XRRichText control is exported to XLS and XLSX formats:

Text format

<b>, <i>, <u>, <s>, <strong>, <em>

Line break

<br>

Non-breaking space

&nbsp;

Font

<font face=[font name]>

Font size

<font size=[font size]>

Foreground color

<font color=[color]>

Runtime Examples

Create the XRRichText Control in Code

The following example creates an XRRichText control and specifies HTML content for this control.

using DevExpress.XtraReports.UI;
using System.Drawing;
// ...
public XRRichText createXRRichTextControlHtml() {
    var richTextControl = new XRRichText() {
        Html = "<b><u>Some content goes here...</b></u>",
        SizeF = new SizeF(200.0F, 30.0F)
    };

    return richTextControl;
}

Change The Font of the XRRichText Control’s Content

This example uses the RichEditDocumentServer component to change the style settings of the RichText control’s content loaded from a data source.

using System.Drawing;
using System.Drawing.Printing;
using DevExpress.XtraReports.UI;
using DevExpress.XtraRichEdit;
// ...
private void xrRichText1_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e) {
    XRRichText richText = (XRRichText)sender;

    using (RichEditDocumentServer docServer = new RichEditDocumentServer()) {
        docServer.RtfText = richText.Rtf;
        docServer.Document.DefaultCharacterProperties.FontName = richText.Font.ToString();
        docServer.Document.DefaultCharacterProperties.FontSize = 15;
        docServer.Document.DefaultCharacterProperties.ForeColor = Color.Green;
        richText.Rtf = docServer.RtfText;
    }
}

Limitations

  • The XRRichText control does not load headers, footers, footnotes, page breaks, and margins from RTF files. If you need to load margins of the RTF document, use the RichEditDocumentServer component to get the loaded document’s margin settings, and then adjust the XRRichText control’s position and width to these settings.
  • The XRRichText control does not support vertical text. The control loads vertical text from RTF files as a horizontal textbox.
  • The XRRichText control may render the specified content incorrectly (for instance, characters may overlap) if the specified content has the Character Spacing’s Scale property set to a non-default value.
  • In web applications, the inline client Rich Text Editor in the XRRichText control does not support Right-To-Left mode.
  • The XRRichText control does not display content with enabled Track Changes feature in an RTF document. All revisions must be accepted before the XRRichText control can display them.
  • The XRRichText control cannot paginate RTF content during export.
  • The XRRichText control cannot ensure that its content is correctly split between report pages if the value of LineSpacing is smaller than the font size.

Implements

See Also