xtrareports-devexpress-dot-xtrareports-dot-ui-f40e1115.md
A control that displays formatted text in a report.
Namespace : DevExpress.XtraReports.UI
Assembly : DevExpress.XtraReports.v25.2.dll
NuGet Package : DevExpress.Reporting.Core
public class XRRichText :
XRRichTextBase,
ISupportInitialize,
IDisplayNamePropertyContainer
Public Class XRRichText
Inherits XRRichTextBase
Implements ISupportInitialize,
IDisplayNamePropertyContainer
To add the XRRichText control to a report, drag the XRRichText item from the DX:25.2: Report Controls Toolbox tab and drop the item onto the report’s bands.
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.
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:
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 to 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.
You can bind the XRRichText control’s Rtf (or Html) property to a data source field that contains RTF (or 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.
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.
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.
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.
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
|
| |
Font
|
<font face=[font name]>
| |
Font size
|
<font size=[font size]>
| |
Foreground color
|
<font color=[color]>
|
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;
}
Imports DevExpress.XtraReports.UI
Imports System.Drawing
' ...
Public Function createXRRichTextControlHtml() As XRRichText
Dim richTextControl = New XRRichText() With {.Html = "<b><u>Some content goes here...</b></u>", .SizeF = New SizeF(200.0F, 30.0F)}
Return richTextControl
End Function
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;
}
}
Imports System.Drawing
Imports System.Drawing.Printing
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraRichEdit
' ...
Private Sub xrRichText1_BeforePrint(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles xrRichText1.BeforePrint
Dim richText As XRRichText = DirectCast(sender, XRRichText)
Using docServer As 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
End Using
End Sub
View Example: Reporting for WinForms - How to Change Formatting in the XRRichText Control
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.XRRichText control does not support vertical text. The control loads vertical text from RTF files as a horizontal textbox.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.XRRichText control does not support Right-To-Left mode.XRRichText control does not display content if the Track Changes feature is enabled in an RTF document. All revisions must be accepted before the XRRichText control can display the content.XRRichText control cannot paginate RTF content during export.XRRichText control cannot ensure that its content is correctly split between report pages if the LineSpacing property value is less than the font size.XRRichText control does not render HTML links (hyperlinks) on preview. You can use the XRRichText.NavigateUrl property to make the entire XRRichText control function as a hyperlink. HTML links are preserved when you export the report to PDF.XRRichText control’s Html and Rtf properties are not localizable. If you only need to display formatted text in your report, you can use the XRLabel control and optionally enable its AllowMarkupText property. XRLabel supports localization.Object MarshalByRefObject Component XRControl XRFieldEmbeddableControl XRRichTextBase XRRichText XRTextBox
See Also