Back to Devexpress

RichEditControl.Document Property

windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-cad07725.md

latest7.3 KB
Original Source

RichEditControl.Document Property

Provides access to a Document interface specifying the control’s document.

Namespace : DevExpress.XtraRichEdit

Assembly : DevExpress.XtraRichEdit.v25.2.dll

NuGet Package : DevExpress.Win.RichEdit

Declaration

csharp
[Browsable(false)]
public Document Document { get; }
vb
<Browsable(False)>
Public ReadOnly Property Document As Document

Property Value

TypeDescription
Document

A Document interface specifying a document loaded in the control.

|

Remarks

The Document property is the main access point to the RichEdit API.

Note

The Document property gives you access only to the main document body. It means that you cannot access field or bookmark collections located in the header/footer using this property. Call the Section.BeginUpdateHeader - Section.EndUpdateHeader pair to access the Document object related to the header and footer.

Use the Document.Selection property to select a text. The following code snippet illustrates how you can select a range of 69 positions starting from the position 216 in the document:

View Example

csharp
document.LoadDocument("Grimm.docx", DocumentFormat.Docx);
DocumentPosition myStart = document.CreatePosition(69);
DocumentRange myRange = document.CreateRange(myStart, 216);
document.Selection = myRange;
vb
document.LoadDocument("Grimm.docx", DocumentFormat.Docx)
Dim myStart As DocumentPosition = document.CreatePosition(69)
Dim myRange As DocumentRange = document.CreateRange(myStart, 216)
document.Selection = myRange

The following code snippets (auto-collected from DevExpress Examples) contain references to the Document 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.

winforms-rich-edit-text-formatting/CS/Text Formatting Example/Form1.cs#L31

csharp
richEditControl.LoadDocument("Document.docx");
FormatTitleChar(richEditControl.Document);
FormatTitleParagraph(richEditControl.Document);

winforms-richedit-emulate-the-ms-word-status-bar/CS/WindowsFormsApplication1/Form1.cs#L35

csharp
{
    CustomLayoutVisitor visitor = new CustomLayoutVisitor(richEditControl1.Document);
    List<PageLayoutInfo> list = richEditControl1.ActiveView.GetVisiblePageLayoutInfos();

how-to-use-docvariable-fields/CS/DocumentVariablesExample/Form1.cs#L38

csharp
this.Cursor = Cursors.WaitCursor;
richEditControl1.Document.MailMerge(myMergeOptions, richEditControl2.Document);
this.Cursor = Cursors.Default;

how-to-specify-default-font-name-and-size/CS/DefaultDocumentSettingsExample/Form1.cs#L32

csharp
//set the default font for the document loaded in the main RichEditControl
Document document = richEditControl1.Document;
document.DefaultCharacterProperties.FontName = "Arial";

winforms-richedit-document-api/CS/RichEditAPISample/Form1.cs#L464

csharp
{
    Document document = richEditControl.Document;
    document.BeginUpdate();

winforms-rich-edit-text-formatting/VB/Text Formatting Example/Form1.vb#L29

vb
richEditControl.LoadDocument("Document.docx")
FormatTitleChar(richEditControl.Document)
FormatTitleParagraph(richEditControl.Document)

winforms-richedit-emulate-the-ms-word-status-bar/VB/WindowsFormsApplication1/Form1.vb#L30

vb
If Me.Visible Then
    Dim visitor As New CustomLayoutVisitor(richEditControl1.Document)
    Dim list As List(Of PageLayoutInfo) = richEditControl1.ActiveView.GetVisiblePageLayoutInfos()

how-to-use-docvariable-fields/VB/DocumentVariablesExample/Form1.vb#L38

vb
Cursor = Cursors.WaitCursor
richEditControl1.Document.MailMerge(myMergeOptions, richEditControl2.Document)
Cursor = Cursors.Default

winforms-spreadsheet-how-to-edit-rich-text/VB/SpreadsheetRichText/RichTextEditForm.vb#L16

vb
Dim richText As RichTextString = cell.GetRichText()
Dim document As Document = RichEditControl1.Document
For Each run As RichTextRun In richText.Runs

winforms-richedit-document-api/VB/RichEditAPISample/Form1.vb#L454

vb
Private Sub evaluator_OnBeforeCompile(ByVal sender As Object, ByVal e As EventArgs)
    Dim document As Document = richEditControl.Document
    document.BeginUpdate()

See Also

RichEditControl Class

RichEditControl Members

DevExpress.XtraRichEdit Namespace