Skip to main content
All docs
V24.1

ContentControlRichText Interface

Rich text content control.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v24.1.Core.dll

NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation

Declaration

public interface ContentControlRichText :
    ContentControlBase

The following members return ContentControlRichText objects:

Remarks

Create a Rich Text Content Control

The code sample below creates a rich text content control:

using DevExpress.XtraRichEdit.API.Native;
using DevExpress.XtraRichEdit;

using (var wordProcessor = new RichEditDocumentServer()) {

    wordProcessor.LoadDocument("Content Controls.docx");
    Document document = wordProcessor.Document;
    var contentControls = document.ContentControls;

    // Insert a form to enter a name:
    var namePosition = document.CreatePosition(document.Paragraphs[0].Range.End.ToInt() - 1);    
    var nameControl = contentControls.InsertRichTextControl(namePosition);

    // Insert a text to a content control:
    var nameTextPosition = document.CreatePosition(nameControl.Range.Start.ToInt() + 1);
    document.InsertText(nameTextPosition, "Click to enter a name");
}

Access Rich Text Content Controls

The SubDocument.ContentControls property returns all content controls in a document. Use the ContentControlBase.ControlType property to determine the content control type.

The code sample below retrieves all rich text controls in a document:

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

using (var wordProcessor = new RichEditDocumentServer()) {

    Document document = wordProcessor.Document;
    var contentControls = document.ContentControls;

    var richTextControls = document.ContentControls.Where(contentControl => contentControl.ControlType == ContentControlType.RichText).Cast<ContentControlRichText>();

    foreach (ContentControlRichText richTextControl in richTextControls)
    {
        // your code here
    }

Modify Rich Text Content Controls

Use the ContentControlRichText class properties to change the rich text control parameters. The code sample below retrieves the rich text content control from the first paragraph and changes its border color:

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

using (var wordProcessor = new RichEditDocumentServer()) {

    wordProcessor.LoadDocument("Content Controls.docx");
    Document document = wordProcessor.Document;
    var contentControls = document.ContentControls;
    var firstParagraph = document.Paragraphs[0];
    for (var i = 0; i < contentControls.Count; i++)
    {
        if (firstParagraph.Range.Contains(contentControls[i].Range.Start) && contentControls[i].ControlType == ContentControlType.RichText)
        {
            ContentControlRichText richText = (ContentControlRichText)contentControls[i];
            richText.Color = Color.Red;
            break;
        }
    }
}

Remove Rich Text Content Controls

The ContentControlCollection.Remove method allows you to remove specific content control. You can also specify whether to keep control’s contents when the controls is removed.

The code sample below removes all rich text controls from the document:

using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;

using (var wordProcessor = new RichEditDocumentServer()) {
    Document document = wordProcessor.Document;
    var contentControls = document.ContentControls;

    for (var i = 0; i < contentControls.Count; i++)
    {
        if (contentControls[i].ControlType == ContentControlType.RichText)
        {
            contentControls.Remove(contentControls[i], true);
        }
    }
}
See Also