ComboBoxContentControl 類別 (2007 系統)

更新: 2008 年 7 月

表示文件上的下拉式方塊。

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

語法

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

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

備註

ComboBoxContentControl 會顯示使用者可選取的項目清單。使用者也可以在 ComboBoxContentControl 中輸入自己的文字。

若要在使用者無法編輯的文字方塊中顯示項目的下拉式清單,請使用 DropDownListContentControl

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

內容控制項

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

範例

下列程式碼範例會將新的 ComboBoxContentControl 加入至文件的開頭。使用者可以選取控制項要顯示的色彩名稱,也可以輸入新色彩的名稱。

這是示範文件層級自訂的版本。若要使用這段程式碼,請將它貼到專案的 ThisDocument 類別中,並從 ThisDocument_Startup 方法呼叫 AddComboBoxControlAtSelection 方法。

Dim comboBoxControl1 As Microsoft.Office.Tools.Word.ComboBoxContentControl

Private Sub AddComboBoxControlAtSelection()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Select()
    comboBoxControl1 = Me.Controls.AddComboBoxContentControl("comboBoxControl1")
    With comboBoxControl1
        .DropDownListEntries.Add("Red", "Red", 0)
        .DropDownListEntries.Add("Green", "Green", 1)
        .DropDownListEntries.Add("Blue", "Blue", 2)
        .PlaceholderText = "Choose a color, or enter your own"
    End With
End Sub
private Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl1;

private void AddComboBoxControlAtSelection()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Select();

    comboBoxControl1 = this.Controls.AddComboBoxContentControl("comboBoxControl1");
    comboBoxControl1.DropDownListEntries.Add("Red", "Red", 0);
    comboBoxControl1.DropDownListEntries.Add("Green", "Green", 1);
    comboBoxControl1.DropDownListEntries.Add("Blue", "Blue", 2);
    comboBoxControl1.PlaceholderText = "Choose a color, or enter your own";
}

這是示範應用程式層級增益集的版本。若要使用這段程式碼,請將它貼到專案的 ThisAddIn 類別中,並從 ThisAddIn_Startup 方法呼叫 AddComboBoxControlAtSelection 方法。

Dim comboBoxControl1 As Microsoft.Office.Tools.Word.ComboBoxContentControl

Private Sub AddComboBoxControlAtSelection()
    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()
    comboBoxControl1 = vstoDoc.Controls.AddComboBoxContentControl("comboBoxControl1")
    With comboBoxControl1
        .DropDownListEntries.Add("Red", "Red", 0)
        .DropDownListEntries.Add("Green", "Green", 1)
        .DropDownListEntries.Add("Blue", "Blue", 2)
        .PlaceholderText = "Choose a color, or enter your own"
    End With
End Sub
private Microsoft.Office.Tools.Word.ComboBoxContentControl comboBoxControl1;

private void AddComboBoxControlAtSelection()
{
    if (this.Application.ActiveDocument == null)
        return;

    Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
    vstoDoc.Paragraphs[1].Range.Select();

    comboBoxControl1 = vstoDoc.Controls.AddComboBoxContentControl(
        "comboBoxControl1");
    comboBoxControl1.DropDownListEntries.Add("Red", "Red", 0);
    comboBoxControl1.DropDownListEntries.Add("Green", "Green", 1);
    comboBoxControl1.DropDownListEntries.Add("Blue", "Blue", 2);
    comboBoxControl1.PlaceholderText = "Choose a color, or enter your own";            
}

繼承階層架構

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

執行緒安全

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

請參閱

參考

ComboBoxContentControl 成員

Microsoft.Office.Tools.Word 命名空間

其他資源

內容控制項

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

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

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

變更記錄

日期

記錄

原因

2008 年 7 月

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

SP1 功能變更。