XRRichText.Rtf Property
Bindable. Gets or sets RTF content for the XRRichText control.
Namespace: DevExpress.XtraReports.UI
Assembly: DevExpress.XtraReports.v24.1.dll
NuGet Package: DevExpress.Reporting.Core
Declaration
Property Value
Type | Description |
---|---|
String | The control’s content in the RTF format. |
Remarks
Use one of the following ways to supply RTF content to the XRRichText‘s Rtf property:
Copy From an External Resource
To add RTF content from an external resource, copy the content, double-click the control, and paste the content in the control’s in-place editor.
Load From a File
To load content from an RTF file (.rtf, .docx, .txt) to the XRRichText control, click the control’s smart tag and select Load File in the invoked actions list.
Select an RTF 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.
Limitations
- The XRRichText control does not load headers, footers, footnotes, page breaks, or margins from RTF files. If you want to load margins, 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.
Load From a Data Source
You can bind the Rtf property to a data source field that contains RTF content. Click the control’s smart tag, expand the Rtf 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.
This creates the XRRichText control whose Rtf property is bound to the selected field.
Use expression bindings to specify a string that uses data from several data fields or to apply additional formatting to data. Click the Rtf Expression option’s ellipsis button
and use the invoked Expression Editor to specify an expression.
Note
When you use expression bindings to supply content to the XRRichText‘s Rtf property, 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.
Examples
Create the XRRichText Control in Code
The following example creates an XRRichText control and specifies RTF content for this control.
using DevExpress.XtraReports.UI;
using System.Drawing;
// ...
public XRRichText createXRRichTextControlRtf() {
var richTextControl = new XRRichText() {
Rtf = "{\\rtf1\\ansi\\deff0 "
+ "{\\fonttbl {\f0 Arial;}}"
+ "\\f0\\fs20 Some content goes here...}",
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;
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Rtf property.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.