Skip to main content
All docs
V24.1

ContentControlCheckbox Interface

Checkbox 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 ContentControlCheckbox :
    ContentControlBase

The following members return ContentControlCheckbox objects:

Remarks

Create a Check Box Content Control

The code sample below shows how to create a checkbox content control:

check box

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

using (var wordProcessor = new RichEditDocumentServer()) {
    wordProcessor.CreateNewDocument();
    Document document = wordProcessor.Document;
    var checkbox = document.ContentControls.InsertCheckboxControl(document.CreatePosition(0));
    checkbox.Title = "Check box";
    checkbox.Checked = true;

    wordProcessor.SaveDocument("Content Controls.docx", DocumentFormat.OpenXml);
}

Access Check Box 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 checkboxes 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 checkBoxes = document.ContentControls.Where(contentControl => contentControl.ControlType == ContentControlType.Checkbox).Cast<ContentControlCheckbox>();

    foreach ( var checkBox in checkBoxes )
    {
        // your code here
    }

Modify Check Box Content Controls

Use the ContentControlCheckbox class properties to change the checkbox parameters. The code sample below retrieves the checkbox from the first paragraph and changes its check marker:

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.Checkbox) {
          ContentControlCheckbox checkBox = (ContentControlCheckbox)contentControls[i];

          checkBox.CheckedSymbolStyle.Character = '*';
          checkBox.CheckedSymbolStyle.FontName = "Arial";
          break;
      }
      wordProcessor.SaveDocument("Content Controls.docx", DocumentFormat.OpenXml);
  }
}

Remove Check Box 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 checkboxes 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.Checkbox)
        {
            contentControls.Remove(contentControls[i], true);
        }
    }
}
See Also