ComboBoxContentControl 介面

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

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

語法

'宣告
<GuidAttribute("fff2d316-e224-4cd9-a10c-3edf95689a6d")> _
Public Interface ComboBoxContentControl _
    Inherits ContentControlBase, IBindableComponent, IComponent, IDisposable,  _
    ISupportInitialize
[GuidAttribute("fff2d316-e224-4cd9-a10c-3edf95689a6d")]
public interface ComboBoxContentControl : ContentControlBase, 
    IBindableComponent, IComponent, IDisposable, ISupportInitialize

ComboBoxContentControl 型別會公開下列成員。

屬性

  名稱 說明
公用屬性 Application 取得 Microsoft.Office.Interop.Word.Application,代表 Microsoft Office Word 目前的執行個體。
公用屬性 BindingContext 取得或設定 IBindableComponent 的 Currency 管理員集合。 (繼承自 IBindableComponent)。
公用屬性 Container 基礎架構。 (繼承自 ContentControlBase)。
公用屬性 ContainerComponent 基礎架構。 (繼承自 ContentControlBase)。
公用屬性 Creator 取得 32 位元整數,表示在其中建立 ComboBoxContentControl 的應用程式。
公用屬性 DataBindings 取得這個 IBindableComponent 的資料繫結物件集合。 (繼承自 IBindableComponent)。
公用屬性 DefaultDataSourceUpdateMode 取得或設定 ContentControlBase 的預設 DataSourceUpdateMode。 (繼承自 ContentControlBase)。
公用屬性 DefaultTextStyle 取得用來格式化 ComboBoxContentControl 中之文字的字元樣式名稱。
公用屬性 DropDownListEntries 取得 ComboBoxContentControl 所顯示的項目集合。
公用屬性 ID 取得識別內容控制項的唯一號碼。 (繼承自 ContentControlBase)。
公用屬性 InnerObject 取得 Microsoft.Office.Tools.Word.ContentControlBase 的基礎 Microsoft.Office.Interop.Word.ContentControl 物件。 (繼承自 ContentControlBase)。
公用屬性 LockContentControl 取得或設定值,這個值指定是否可以從文件中刪除 ComboBoxContentControl。
公用屬性 LockContents 取得或設定值,這個值指定是否可以編輯 ComboBoxContentControl 的內容。
公用屬性 MultiLine 取得或設定值,這個值指定 ComboBoxContentControl 是否可以包含分行符號。
公用屬性 Parent 取得 ComboBoxContentControl 的父代 (Parent)。
公用屬性 ParentContentControl 取得以巢狀方式置於另一個內容控制項中之 ComboBoxContentControl 的父內容控制項。
公用屬性 PlaceholderText 取得或設定 ComboBoxContentControl 中顯示的文字,直到該文字被使用者動作或其他作業變更為止。
公用屬性 Range 取得表示 ComboBoxContentControl 內容的 Range
公用屬性 ShowingPlaceholderText 取得值,這個值表示 ComboBoxContentControl 目前是否顯示預留位置文字。
公用屬性 Site 取得或設定與 IComponent 相關聯的 ISite。 (繼承自 IComponent)。
公用屬性 Tag 取得或設定要與 ComboBoxContentControl 產生關聯的字串。
公用屬性 Temporary 取得或設定值,這個值指定編輯 ComboBoxContentControl 控制項時,是否會從文件中自動刪除此控制項。
公用屬性 Text 取得或設定 ComboBoxContentControl 中的文字。
公用屬性 Title 取得或設定 ComboBoxContentControl 的標題。
公用屬性 XMLMapping 取得 Microsoft.Office.Interop.Word.XMLMapping,表示 ComboBoxContentControl 和自訂 XML 組件的項目之間的繫結。

回頁首

方法

  名稱 說明
公用方法 BeginInit 表示物件正在啟動初始設定。 (繼承自 ISupportInitialize)。
公用方法 Copy 將 ComboBoxContentControl 從文件複製到 [剪貼簿]。
公用方法 Cut 從文件移除 ComboBoxContentControl 並將它加入至 [剪貼簿]。
公用方法 Delete 從文件中刪除動態建立的內容控制項,並從文件中的 ControlCollection 移除這個內容控制項。 (繼承自 ContentControlBase)。
公用方法 Dispose 執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。 (繼承自 IDisposable)。
公用方法 EndInit 表示物件已完成初始設定。 (繼承自 ISupportInitialize)。
公用方法 SetPlaceholderText 顯示 T:Microsoft.Office.Interop.Word.BuildingBlockRange 或字串中的文字,做為 ComboBoxContentControl 中的預留位置文字。

回頁首

事件

  名稱 說明
公用事件 Added 在內容控制項加入至文件之後發生。 (繼承自 ContentControlBase)。
公用事件 BindingContextChanged ContentControlBaseBindingContext 屬性值變更時發生。 (繼承自 ContentControlBase)。
公用事件 ContentUpdating 如果內容控制項已繫結至自訂 XML 組件,只在 Microsoft Office Word 更新內容控制項中的文字之前發生。 (繼承自 ContentControlBase)。
公用事件 Deleting 只在內容控制項從文件中刪除之前發生。 (繼承自 ContentControlBase)。
公用事件 Disposed 表示處理元件的 Disposed 事件的方法。 (繼承自 IComponent)。
公用事件 Entering 當使用者在內容控制項中按一下或以程式設計方式將游標移至內容控制項時發生。 (繼承自 ContentControlBase)。
公用事件 Exiting 當使用者在內容控制項外部按一下或以程式設計方式將游標移至內容控制項外部時發生。 (繼承自 ContentControlBase)。
公用事件 StoreUpdating 只在 Microsoft Office Word 更新已繫結至內容控制項之自訂 XML 組件中的資料之前發生 (也就是,在內容控制項中的文字變更之後)。 (繼承自 ContentControlBase)。
公用事件 Validated 在成功驗證內容控制項時發生。 (繼承自 ContentControlBase)。
公用事件 Validating 驗證內容控制項的內容時發生。 (繼承自 ContentControlBase)。

回頁首

備註

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

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

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

注意事項注意事項

此介面是由 Visual Studio Tools for Office Runtime 所實作, 並不能實作於您的程式碼中。 如需詳細資訊,請參閱 Visual Studio Tools for Office Runtime 概觀

內容控制項

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

使用方式

本文件說明此型別用於以 .NET Framework 4 為目標之 Office 專案的版本。在以 .NET Framework 3.5 為目標的專案中,此型別可能會有不同的成員,而為此型別提供的程式碼範例可能無法運作。 如需此型別在以 .NET Framework 3.5 為目標之專案中的相關文件,請參閱下列 Visual Studio 2008 文件中的參考章節:https://go.microsoft.com/fwlink/?LinkId=160658 (英文)。

範例

下列程式碼範例會將新的 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 = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    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 = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    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";            
}

請參閱

參考

Microsoft.Office.Tools.Word 命名空間

其他資源

內容控制項

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

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

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