Export (0) Print
Expand All

PlainTextContentControl Class (2007 System)

Updated: July 2008

Represents a block of text in a document.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)

[DefaultBindingPropertyAttribute("Text")]
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class PlainTextContentControl : ContentControlBase, 
	ISupportInitializeControl, ISupportInitialize

A PlainTextContentControl can contain only text. You can format the text in a PlainTextContentControl, but all of the text in the control automatically has the same formatting. For example, if you italicize one word of a sentence that is in a PlainTextContentControl, all the text inside the control is italicized.

To access the text in a PlainTextContentControl, use the Text property. By default, a PlainTextContentControl cannot contain line breaks. To change this behavior, use the MultiLine property.

To create a document region that can contain text and many other types of content, including tables, pictures, or other content controls, use a RichTextContentControl.

Content Controls

The PlainTextContentControl is one of eight types of content controls that you can use to design documents and templates in Microsoft Office Word. Content controls have a user interface (UI) that has controlled input like a form. You can use content controls to prevent users from editing protected sections of the document or template, and you can also bind content controls to a data source. For more information, see Content Controls.

The following code example adds a new PlainTextContentControl to the beginning of the document.

This version is for a document-level customization. To use this code, paste it into the ThisDocument class in your project, and call the AddTextControlAtSelection method from the ThisDocument_Startup method.

private Microsoft.Office.Tools.Word.PlainTextContentControl textControl1;

private void AddTextControlAtSelection()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Select();

    textControl1 = this.Controls.AddPlainTextContentControl("textControl1");
    textControl1.PlaceholderText = "Enter your first name";
}

This version is for an application-level add-in. To use this code, paste it into the ThisAddIn class in your project, and call the AddTextControlAtSelection method from the ThisAddIn_Startup method.

private Microsoft.Office.Tools.Word.PlainTextContentControl textControl1;

private void AddTextControlAtSelection()
{
    if (this.Application.ActiveDocument == null)
        return;

    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
    vstoDoc.Paragraphs[1].Range.Select();

    textControl1 = vstoDoc.Controls.AddPlainTextContentControl("textControl1");
    textControl1.PlaceholderText = "Enter your first name";
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Date

History

Reason

July 2008

Added a version of the code example for an application-level add-in.

SP1 feature change.

Community Additions

ADD
Show:
© 2014 Microsoft