PlainTextContentControl.PlaceholderText Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the text that is displayed in the PlainTextContentControl until the text is changed by a user action or some other operation.
public:
property System::String ^ PlaceholderText { System::String ^ get(); void set(System::String ^ value); };
public string PlaceholderText { get; set; }
member this.PlaceholderText : string with get, set
Public Property PlaceholderText As String
Property Value
The text that is displayed in the control until the text is changed by a user action or some other operation.
Examples
The following code example adds a new PlainTextContentControl to the beginning of the document. The example sets the PlaceholderText property to a string that prompts the user to type his or her first name.
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";
}
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
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 = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
vstoDoc.Paragraphs[1].Range.Select();
textControl1 = vstoDoc.Controls.AddPlainTextContentControl("textControl1");
textControl1.PlaceholderText = "Enter your first name";
}
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 = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
vstoDoc.Paragraphs(1).Range.Select()
plainTextControl1 = vstoDoc.Controls.AddPlainTextContentControl("plainTextControl1")
plainTextControl1.PlaceholderText = "Enter your first name"
End Sub
Remarks
The placeholder text is displayed until a user edits the control, the control is populated with data from a data source, or the control's contents are deleted.
To set the placeholder text to text that is in a BuildingBlock or a Range, use the SetPlaceholderText method.