ContentControlPlainText Interface
Plain text content control.
Namespace: DevExpress.XtraRichEdit.API.Native
Assembly: DevExpress.RichEdit.v24.1.Core.dll
NuGet Packages: DevExpress.RichEdit.Core, DevExpress.Win.Navigation
Declaration
Related API Members
The following members return ContentControlPlainText objects:
Remarks
Create a Plain Text Content Control
The code sample below creates a plain text content control and inserts text to is:
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.InsertPlainTextControl(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 Plain 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 plain 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 plainTextControls = document.ContentControls.Where(contentControl => contentControl.ControlType == ContentControlType.PlainText).Cast<ContentControlPlainText>();
foreach (ContentControlPlainText plainTextControl in plainTextControls)
{
// your code here
}
Modify Plain Text Content Controls
Use the ContentControlPlainText
class properties to change the plain text control parameters. The code sample below retrieves the plain 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.PlainText)
{
ContentControlPlainText plainText = (ContentControlPlainText)contentControls[i];
plainText.Color = Color.Red;
break;
}
}
}
Remove Plain 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 plain 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.PlainText)
{
contentControls.Remove(contentControls[i], true);
}
}
}