获取或设置在用户操作或某个其他操作更改文本之前在 DropDownListContentControl 中显示的文本。
命名空间:  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
在用户操作或某个其他操作更改文本之前,在控件中显示的文本。
备注
在用户选择某项、在控件中填充数据源的数据之前,占位符文本会一直显示。
若要将占位符文本设置为 BuildingBlock 或 Range 中的文本,请使用 SetPlaceholderText 方法。
示例
下面的代码示例会在文档开头添加一个新的 DropDownListContentControl。 通过该控件,用户可以选择一周中任意一天的名称。 该示例会将 PlaceholderText 属性设置为一个字符串,以提示用户选择某一天。
此版本针对的是文档级自定义项。 若要使用此代码,请将其粘贴到项目内的 ThisDocument 类中,然后从 ThisDocument_Startup 方法中调用 AddDropDownListControlAtSelection 方法。
Dim dropDownListControl1 As Microsoft.Office.Tools.Word.DropDownListContentControl
Private Sub AddDropDownListControlAtSelection()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Select()
    dropDownListControl1 = Me.Controls.AddDropDownListContentControl("dropDownListControl1")
    With dropDownListControl1
        .DropDownListEntries.Add("Monday", "Monday", 0)
        .DropDownListEntries.Add("Tuesday", "Tuesday", 1)
        .DropDownListEntries.Add("Wednesday", "Wednesday", 2)
        .PlaceholderText = "Choose a day"
    End With
End Sub
private Microsoft.Office.Tools.Word.DropDownListContentControl dropDownListControl1;
private void AddDropDownListControlAtSelection()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Select();
    dropDownListControl1 = this.Controls.AddDropDownListContentControl("dropDownListControl1");
    dropDownListControl1.DropDownListEntries.Add("Monday", "Monday", 0);
    dropDownListControl1.DropDownListEntries.Add("Tuesday", "Tuesday", 1);
    dropDownListControl1.DropDownListEntries.Add("Wednesday", "Wednesday", 2);
    dropDownListControl1.PlaceholderText = "Choose a day";
}
此版本针对的是应用程序级外接程序。 若要使用此代码,请将其粘贴到项目内的 ThisAddIn 类中,然后从 ThisAddIn_Startup 方法中调用 AddDropDownListControlAtSelection 方法。
Dim dropDownListControl1 As Microsoft.Office.Tools.Word.DropDownListContentControl
Private Sub AddDropDownListControlAtSelection()
    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()
    dropDownListControl1 = vstoDoc.Controls.AddDropDownListContentControl("dropDownListControl1")
    With dropDownListControl1
        .DropDownListEntries.Add("Monday", "Monday", 0)
        .DropDownListEntries.Add("Tuesday", "Tuesday", 1)
        .DropDownListEntries.Add("Wednesday", "Wednesday", 2)
        .PlaceholderText = "Choose a day"
    End With
End Sub
private Microsoft.Office.Tools.Word.DropDownListContentControl dropDownListControl1;
private void AddDropDownListControlAtSelection()
{
    if (this.Application.ActiveDocument == null)
        return;
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
    vstoDoc.Paragraphs[1].Range.Select();
    dropDownListControl1 = vstoDoc.Controls.AddDropDownListContentControl("dropDownListControl1");
    dropDownListControl1.DropDownListEntries.Add("Monday", "Monday", 0);
    dropDownListControl1.DropDownListEntries.Add("Tuesday", "Tuesday", 1);
    dropDownListControl1.DropDownListEntries.Add("Wednesday", "Wednesday", 2);
    dropDownListControl1.PlaceholderText = "Choose a day";
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。