RichTextContentControl.PlaceholderText Property
Gets or sets the text that is displayed in the RichTextContentControl until the text is changed by a user action or some other operation.
Namespace: Microsoft.Office.Tools.Word
Assembly: Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)
Syntax
'Declaration
Property PlaceholderText As String
string PlaceholderText { get; set; }
Property Value
Type: System.String
The text that is displayed in the control until the text is changed by a user action or some other operation.
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 Microsoft.Office.Interop.Word.BuildingBlock or a Range, use the SetPlaceholderText method.
Examples
The following code example adds a new RichTextContentControl 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 AddRichTextControlAtSelection method from the ThisDocument_Startup method.
Dim richTextControl1 As Microsoft.Office.Tools.Word.RichTextContentControl
Private Sub AddRichTextControlAtSelection()
Me.Paragraphs(1).Range.InsertParagraphBefore()
Me.Paragraphs(1).Range.Select()
richTextControl1 = Me.Controls.AddRichTextContentControl("richTextControl1")
richTextControl1.PlaceholderText = "Enter your first name"
End Sub
private Microsoft.Office.Tools.Word.RichTextContentControl richTextControl1;
private void AddRichTextControlAtSelection()
{
this.Paragraphs[1].Range.InsertParagraphBefore();
this.Paragraphs[1].Range.Select();
richTextControl1 = this.Controls.AddRichTextContentControl("richTextControl1");
richTextControl1.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 AddRichTextControlAtSelection method from the ThisAddIn_Startup method.
Dim richTextControl1 As Microsoft.Office.Tools.Word.RichTextContentControl
Private Sub AddRichTextControlAtSelection()
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()
richTextControl1 = vstoDoc.Controls.AddRichTextContentControl("richTextControl1")
richTextControl1.PlaceholderText = "Enter your first name"
End Sub
private Microsoft.Office.Tools.Word.RichTextContentControl richTextControl1;
private void AddRichTextControlAtSelection()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
vstoDoc.Paragraphs[1].Range.Select();
richTextControl1 = vstoDoc.Controls.AddRichTextContentControl("richTextControl1");
richTextControl1.PlaceholderText = "Enter your first name";
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.