Quantcast
Channel: Developer Express Inc.
Viewing all articles
Browse latest Browse all 2370

Word Processing Document API, Rich Text Editors (WinForms and WPF) — Content Controls (v23.2)

$
0
0

As you know, content controls are interactive UI elements (text fields, drop-down lists, date pickers) designed to enter and manage information on-screen. Content controls are often used within templates/forms to standardize document formatting and streamline data entry. DevExpress word processing product libraries (Word Processing Document API, Rich Text Editors for WinForms and WPF) ship with content control support (v23.2+). Documents with content controls can be processed, printed, or exported to PDF. In this blog post, I’ll describe implementation options available to you.

Content controls include the following:

  • Building Block Gallery (access and edit only)
    Predefined blocks of content, such as text, images, or other document elements.
  • Check Box
    An interactive check box.
  • Combo Box
    A combination of a drop-down list and a single-line editable textbox.
  • Date Picker
    A pop-up calendar.
  • Drop-Down List
    A list of selectable values.
  • Plain Text
    A text box for simple text input.
  • Picture (access and edit only)
    A placeholder for an image.
  • Repeating Section (access and edit only)
    Repeats a content section (for example, a list of items) within a document.
  • Rich Text
    A text box used for rich-formatted text.

With the help of our content control API (available in v23.2+), you can create, edit, and remove content controls within a document. Use the Document.ContentControls property as an entry point. The following code snippet generates plain text, drop-down list, and date picker content controls:

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

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

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

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

    // Insert an appointment type drop-down list:
    var listPosition = document.CreatePosition(document.Paragraphs[1].Range.End.ToInt() - 1);
    var listControl = contentControls.InsertDropDownListControl(listPosition);

    // Add items to a drop-down list:
    listControl.AddItem("First Appointment", "First Appointment");
    listControl.AddItem("Follow-Up Appointment", "Follow-Up Appointment");
    listControl.AddItem("Laboratory Results Check", "Laboratory Results Check");

    listControl.SelectedItemIndex = 1;

    // Insert a date picker to specify appointment date:
    var datePosition = document.CreatePosition(document.Paragraphs[2].Range.End.ToInt() - 1);
    var datePicker = contentControls.InsertDatePickerControl(datePosition);
    datePicker.DateFormat = "dddd, MMMM dd, yyyy";
}

Please refer to the following help topic for additional information/examples:Content Controls in Word Processing Documents

Desktop Rich Text Editor (WinForms and WPF)

Our Rich Text Editors (WinForms and WPF) can display content controls. You can also input and select data as needs dictate.

Please note: At present, DevExpress Rich Text Editors do not ship with content control-related UI elements (toolbar items, dialogs).

Your Feedback Matters

As always, your feedback is highly appreciated.  Your responses to the following survey will help us fine-tune development strategies in future release cycles.


Viewing all articles
Browse latest Browse all 2370

Trending Articles