PlainTextContentControl Class (2007 System)
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)
Syntax
'Declaration
<DefaultBindingPropertyAttribute("Text")> _
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public NotInheritable Class PlainTextContentControl _
Inherits ContentControlBase _
Implements ISupportInitializeControl, ISupportInitialize
'Usage
Dim instance As PlainTextContentControl
[DefaultBindingPropertyAttribute("Text")]
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class PlainTextContentControl : ContentControlBase,
ISupportInitializeControl, ISupportInitialize
[DefaultBindingPropertyAttribute(L"Text")]
[PermissionSetAttribute(SecurityAction::Demand, Name = L"FullTrust")]
public ref class PlainTextContentControl sealed : public ContentControlBase,
ISupportInitializeControl, ISupportInitialize
public final class PlainTextContentControl extends ContentControlBase implements ISupportInitializeControl, ISupportInitialize
Remarks
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.
Examples
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.
Dim plainTextControl1 As Microsoft.Office.Tools.Word.PlainTextContentControl
Private Sub AddPlainTextControlAtSelection()
Me.Paragraphs(1).Range.InsertParagraphBefore()
Me.Paragraphs(1).Range.Select()
plainTextControl1 = Me.Controls.AddPlainTextContentControl("plainTextControl1")
plainTextControl1.PlaceholderText = "Enter your first name"
End Sub
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.
Dim plainTextControl1 As Microsoft.Office.Tools.Word.PlainTextContentControl
Private Sub AddPlainTextControlAtSelection()
If Me.Application.ActiveDocument Is Nothing Then
Return
End If
Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
vstoDoc.Paragraphs(1).Range.Select()
plainTextControl1 = vstoDoc.Controls.AddPlainTextContentControl("plainTextControl1")
plainTextControl1.PlaceholderText = "Enter your first name"
End Sub
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";
}
Inheritance Hierarchy
System.Object
Microsoft.VisualStudio.Tools.Office.RemoteComponent
Microsoft.VisualStudio.Tools.Office.RemoteBindableComponent
Microsoft.Office.Tools.Word.ContentControlBase
Microsoft.Office.Tools.Word.PlainTextContentControl
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also
Reference
PlainTextContentControl Members
Microsoft.Office.Tools.Word Namespace
Other Resources
How to: Add Content Controls to Word Documents
How to: Protect Parts of Documents by Using Content Controls
Walkthrough: Creating a Template By Using Content Controls
Walkthrough: Binding Content Controls to Custom XML Parts
Change History
Date |
History |
Reason |
---|---|---|
July 2008 |
Added a version of the code example for an application-level add-in. |
SP1 feature change. |