ComboBoxContentControl 介面

定義

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

public interface class ComboBoxContentControl : IDisposable, Microsoft::Office::Tools::Word::ContentControlBase, System::ComponentModel::IComponent, System::ComponentModel::ISupportInitialize, System::Windows::Forms::IBindableComponent
[System.Runtime.InteropServices.Guid("fff2d316-e224-4cd9-a10c-3edf95689a6d")]
public interface ComboBoxContentControl : IDisposable, Microsoft.Office.Tools.Word.ContentControlBase, System.ComponentModel.IComponent, System.ComponentModel.ISupportInitialize, System.Windows.Forms.IBindableComponent
[<System.Runtime.InteropServices.Guid("fff2d316-e224-4cd9-a10c-3edf95689a6d")>]
type ComboBoxContentControl = interface
    interface ContentControlBase
    interface IBindableComponent
    interface IComponent
    interface IDisposable
    interface ISupportInitialize
Public Interface ComboBoxContentControl
Implements ContentControlBase, IBindableComponent, IComponent, IDisposable, ISupportInitialize
屬性
實作

範例

下列程式代碼範例會將新的 ComboBoxContentControl 新增至檔的開頭。 用戶可以選取控件所顯示的色彩名稱,也可以輸入新色彩的名稱。

此版本適用於檔層級自定義。 若要使用此程式碼,請將它貼到專案中的 ThisDocument 類別,然後從 ThisDocument_Startup 方法呼叫 AddComboBoxControlAtSelection 方法。

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

此版本適用於應用層級載入宏。 若要使用此程式碼,請將它貼到專案中的 ThisAddIn 類別,然後從 ThisAddIn_Startup 方法呼叫 AddComboBoxControlAtSelection 方法。

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

備註

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

若要在使用者無法編輯的文字框中顯示專案的下拉式清單,請使用 DropDownListContentControl

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

注意

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

內容控制項

ComboBoxContentControl是八種內容控件的其中一種,可用來在 Microsoft Office Word 中設計檔和範本。 內容控制項具有使用者介面 (UI) ,該使用者介面具有控件輸入,例如表單。 您可以使用內容控制項來防止使用者編輯檔或範本的受保護區段,也可以將內容控制項系結至數據來源。 如需詳細資訊,請參閱 Content Controls

使用方式

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

屬性

Application

取得 Application,代表 Microsoft Office Word 目前的執行個體。

Container

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

(繼承來源 ContentControlBase)
ContainerComponent

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

(繼承來源 ContentControlBase)
Creator

取得 32 位元整數,表示在其中建立 ComboBoxContentControl 的應用程式。

DefaultDataSourceUpdateMode

取得或設定 DataSourceUpdateMode 的預設 ContentControlBase

(繼承來源 ContentControlBase)
DefaultTextStyle

取得用來格式化 ComboBoxContentControl 中之文字的字元樣式名稱。

DropDownListEntries

取得 ComboBoxContentControl 所顯示的項目集合。

ID

取得識別內容控制項的唯一號碼。

(繼承來源 ContentControlBase)
InnerObject

取得 ContentControlBase 的基礎 ContentControl 物件。

(繼承來源 ContentControlBase)
LockContentControl

取得或設定值,指定是否可從文件刪除 ComboBoxContentControl

LockContents

取得或設定值,指定是否可以編輯 ComboBoxContentControl 的內容。

MultiLine

取得或設定值,這個值指定 ComboBoxContentControl 是否可以包含分行符號。

Parent

取得 ComboBoxContentControl 的父系。

ParentContentControl

取得以巢狀方式置於另一個內容控制項中之 ComboBoxContentControl 的父內容控制項。

PlaceholderText

取得或設定 ComboBoxContentControl 中顯示的文字,直到該文字被使用者動作或其他作業變更為止。

Range

取得 Range,代表 ComboBoxContentControl 的內容。

ShowingPlaceholderText

取得值,這個值表示 ComboBoxContentControl 目前是否顯示預留位置文字。

Tag

取得或設定要與 ComboBoxContentControl 產生關聯的字串。

Temporary

取得或設定值,這個值指定編輯 ComboBoxContentControl 控制項時,是否會從文件中自動刪除此控制項。

Text

取得或設定 ComboBoxContentControl 中的文字。

Title

取得或設定 ComboBoxContentControl 的標題。

XMLMapping

取得 XMLMapping,代表 ComboBoxContentControl 與自訂 XML 組件中的元素之間的繫結。

方法

Copy()

ComboBoxContentControl 從文件複製到 [剪貼簿]。

Cut()

從文件移除 ComboBoxContentControl 並將它加入至 [剪貼簿]。

Delete(Boolean)

從文件中刪除動態建立的內容控制項,並從文件中的 ControlCollection 將它移除。

(繼承來源 ContentControlBase)
SetPlaceholderText(BuildingBlock, Range, String)

顯示 T:Microsoft.Office.Interop 中的文字。Word。BuildingBlock、、 Range或字串做為 中的ComboBoxContentControl佔位元文字。

事件

Added

在內容控制項加入至文件之後發生。

(繼承來源 ContentControlBase)
BindingContextChanged

BindingContextContentControlBase 屬性值變更時發生。

(繼承來源 ContentControlBase)
ContentUpdating

如果內容控制項已繫結至自訂 XML 組件,只在 Microsoft Office Word 更新內容控制項中的文字之前發生。

(繼承來源 ContentControlBase)
Deleting

只在內容控制項從文件中刪除之前發生。

(繼承來源 ContentControlBase)
Entering

當使用者在內容控制項中按一下或以程式設計方式將游標移至內容控制項時發生。

(繼承來源 ContentControlBase)
Exiting

當使用者在內容控制項外部按一下或以程式設計方式將游標移至內容控制項外部時發生。

(繼承來源 ContentControlBase)
StoreUpdating

就在 Microsoft Office Word 更新繫結至內容控制項的自訂 XML 組件資料之前 (也就是內容控制項中的文字變更之後)。

(繼承來源 ContentControlBase)
Validated

在成功驗證內容控制項時發生。

(繼承來源 ContentControlBase)
Validating

驗證內容控制項的內容時發生。

(繼承來源 ContentControlBase)

適用於