PlainTextContentControl.PlaceholderText 属性

获取或设置在用户操作或某个其他操作更改文本之前在 PlainTextContentControl 中显示的文本。

命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word(在 Microsoft.Office.Tools.Word.dll 中)

语法

声明
Property PlaceholderText As String
    Get
    Set
string PlaceholderText { get; set; }

属性值

类型:System.String
在用户操作或某个其他操作更改文本之前,在控件中显示的文本。

备注

在用户编辑控件、在控件中填充数据源的数据,或者控件内容被删除之前,占位符文本会一直显示。

若要将占位符文本设置为 BuildingBlockRange 中的文本,请使用 SetPlaceholderText 方法。

示例

下面的代码示例会在文档开头添加一个新的 PlainTextContentControl。 该示例会将 PlaceholderText 属性设置为一个字符串,以提示用户键入他或她的名字。

此版本针对的是文档级自定义项。 若要使用此代码,请将其粘贴到项目内的 ThisDocument 类中,然后从 ThisDocument_Startup 方法中调用 AddTextControlAtSelection 方法。

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";
}

此版本针对的是应用程序级外接程序。 若要使用此代码,请将其粘贴到项目内的 ThisAddIn 类中,然后从 ThisAddIn_Startup 方法中调用 AddTextControlAtSelection 方法。

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
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";
}

.NET Framework 安全性

请参见

参考

PlainTextContentControl 接口

Microsoft.Office.Tools.Word 命名空间