DropDownListContentControl 類別 (2007 系統)

更新: 2008 年 7 月

表示文件上的下拉式清單。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v9.0 (在 Microsoft.Office.Tools.Word.v9.0.dll 中)

語法

<DefaultBindingPropertyAttribute("PlaceholderText")> _
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public NotInheritable Class DropDownListContentControl _
    Inherits ContentControlBase _
    Implements ISupportInitializeControl, ISupportInitialize

Dim instance As DropDownListContentControl
[DefaultBindingPropertyAttribute("PlaceholderText")]
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class DropDownListContentControl : ContentControlBase, 
    ISupportInitializeControl, ISupportInitialize

備註

DropDownListContentControl 會顯示使用者可選取的項目清單。

若要存取 DropDownListContentControl 中的項目清單,請使用 DropDownListEntries 屬性。

若要讓使用者從項目清單中選擇或將他們自己的文字加入至控制項中,請使用 ComboBoxContentControl

內容控制項

DropDownListContentControl 是八種內容控制項型別的其中一個,可用來設計 Microsoft Office Word 中的文件和範本。內容控制項有一個使用者介面 (UI) 具有像表單一樣的受控制輸入。您可以使用內容控制項以避免使用者編輯文件或範本中被保護的區段,也可以將內容控制項繫結至資料來源。如需詳細資訊,請參閱內容控制項

範例

下列程式碼範例會將新的 DropDownListContentControl 加入至文件的開頭。使用者可以使用該控制項,選取星期的日期名稱。

這是示範文件層級自訂的版本。若要使用這段程式碼,請將它貼到專案的 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 = Me.Application.ActiveDocument.GetVstoObject()
    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 = this.Application.ActiveDocument.GetVstoObject();
    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";
}

繼承階層架構

System.Object
  Microsoft.VisualStudio.Tools.Office.RemoteComponent
    Microsoft.VisualStudio.Tools.Office.RemoteBindableComponent
      Microsoft.Office.Tools.Word.ContentControlBase
        Microsoft.Office.Tools.Word.DropDownListContentControl

執行緒安全

這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

請參閱

參考

DropDownListContentControl 成員

Microsoft.Office.Tools.Word 命名空間

其他資源

內容控制項

HOW TO:將內容控制項加入至 Word 文件

HOW TO:使用內容控制項保護文件的部分

逐步解說:使用內容控制項建立範本

逐步解說:將內容控制項繫結至自訂 XML 組件

變更記錄

日期

記錄

原因

2008 年 7 月

加入應用程式層級增益集的程式碼範例版本。

SP1 功能變更。