ComboBoxContentControl 介面

定義

代表文件上的下拉式方塊。Represents a combo box on a document.

[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
屬性
實作

範例

下列程式碼範例會將新的新增 ComboBoxContentControl 至檔的開頭。The following code example adds a new ComboBoxContentControl to the beginning of the document. 使用者可以選取控制項所顯示的色彩名稱,也可以輸入新色彩的名稱。Users can select a color name displayed by the control, or they can type the name of a new color.

這個版本適用于檔層級自訂。This version is for a document-level customization. 若要使用此程式碼,請將它貼入 ThisDocument 專案中的類別,並 AddComboBoxControlAtSelection 從方法呼叫方法 ThisDocument_StartupTo use this code, paste it into the ThisDocument class in your project, and call the AddComboBoxControlAtSelection method from the ThisDocument_Startup method.

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

這個版本適用于應用層級增益集。This version is for an application-level add-in. 若要使用此程式碼,請將它貼入 ThisAddIn 專案中的類別,並 AddComboBoxControlAtSelection 從方法呼叫方法 ThisAddIn_StartupTo use this code, paste it into the ThisAddIn class in your project, and call the AddComboBoxControlAtSelection method from the ThisAddIn_Startup method.

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會顯示使用者可以選取的專案清單。A ComboBoxContentControl displays a list of items that users can select. 使用者也可以在中輸入自己的文字 ComboBoxContentControlUsers can also type their own text in a ComboBoxContentControl.

若要在使用者無法編輯的文字方塊中顯示專案的下拉式清單,請使用 DropDownListContentControlTo display a drop-down list of items in a text box that users cannot edit, use a DropDownListContentControl.

若要存取中的專案清單 ComboBoxContentControl ,請使用 DropDownListEntries 屬性。To access the list of items in a ComboBoxContentControl, use the DropDownListEntries property.

注意

這個介面是由 Visual Studio Tools for Office Runtime 實作,This interface is implemented by the Visual Studio Tools for Office runtime. 並不能實作於您的程式碼中。It is not intended to be implemented in your code. 如需詳細資訊,請參閱 Visual Studio Tools for Office Runtime OverviewFor more information, see Visual Studio Tools for Office Runtime Overview.

內容控制項Content Controls

ComboBoxContentControl是八種類型內容控制項的其中一種,您可以用來在 Microsoft Office Word 中設計檔和範本。The ComboBoxContentControl is one of eight types of content controls that you can use to design documents and templates in Microsoft Office Word. 內容控制項有一個使用者介面(UI),其具有如表單的控制輸入。Content controls have a user interface (UI) that has controlled input like a form. 您可以使用內容控制項來防止使用者編輯檔或範本的受保護區段,而且您也可以將內容控制項系結至資料來源。You can use content controls to prevent users from editing protected sections of the document or template, and you can also bind content controls to a data source. 如需詳細資訊,請參閱 Content ControlsFor more information, see Content Controls.

使用量Usage

本文件說明此類型的版本,其會用在目標為 .NET Framework 4 或更新版本的 Office 專案中。This documentation describes the version of this type that is used in Office projects that target the .NET Framework 4 or later. 在以 .NET Framework 3.5 為目標的專案中,此類型可能會有不同的成員,而為此類型提供的程式碼範例可能無法運作。In projects that target the .NET Framework 3.5, this type might have different members and the code examples provided for this type might not work. 如需此類型在以 .NET Framework 3.5 為目標專案中的相關文件,請參閱下列 Visual Studio 2008 文件中的參考章節:http://go.microsoft.com/fwlink/?LinkId=160658For documentation about this type in projects that target the .NET Framework 3.5, see the following reference section in the Visual Studio 2008 documentation: http://go.microsoft.com/fwlink/?LinkId=160658.

屬性

Application

取得 Application,代表 Microsoft Office Word 目前的執行個體。Gets a Application that represents the current instance of Microsoft Office Word.

Container (繼承來源 ContentControlBase)
ContainerComponent (繼承來源 ContentControlBase)
Creator

取得 32 位元整數,表示在其中建立 ComboBoxContentControl 的應用程式。Gets a 32-bit integer that indicates the application in which the ComboBoxContentControl was created.

DefaultDataSourceUpdateMode

取得或設定 DataSourceUpdateMode 的預設 ContentControlBaseGets or sets the default DataSourceUpdateMode for the ContentControlBase.

(繼承來源 ContentControlBase)
DefaultTextStyle

取得用來格式化 ComboBoxContentControl 中之文字的字元樣式名稱。Gets the name of the character style that is used to format text in the ComboBoxContentControl.

DropDownListEntries

取得 ComboBoxContentControl 所顯示的項目集合。Gets the collection of items that are displayed by the ComboBoxContentControl.

ID

取得識別內容控制項的唯一號碼。Gets a unique number that identifies the content control.

(繼承來源 ContentControlBase)
InnerObject

取得 ContentControlBase 的基礎 ContentControl 物件。Gets the underlying ContentControl object for the ContentControlBase.

(繼承來源 ContentControlBase)
LockContentControl

取得或設定值,指定是否可從文件刪除 ComboBoxContentControlGets or sets a value that specifies whether the ComboBoxContentControl can be deleted from the document.

LockContents

取得或設定值,指定是否可以編輯 ComboBoxContentControl 的內容。Gets or sets a value that specifies whether the contents of the ComboBoxContentControl can be edited.

MultiLine

取得或設定值,這個值指定 ComboBoxContentControl 是否可以包含分行符號。Gets or sets a value that specifies whether the ComboBoxContentControl can contain line breaks.

Parent

取得 ComboBoxContentControl 的父代 (Parent)。Gets the parent of the ComboBoxContentControl.

ParentContentControl

取得以巢狀方式置於另一個內容控制項中之 ComboBoxContentControl 的父內容控制項。Gets the parent content control of a ComboBoxContentControl that is nested in another content control.

PlaceholderText

取得或設定 ComboBoxContentControl 中顯示的文字,直到該文字被使用者動作或其他作業變更為止。Gets or sets the text that is displayed in the ComboBoxContentControl until the text is changed by a user action or some other operation.

Range

取得 Range,代表 ComboBoxContentControl 的內容。Gets a Range that represents the contents of the ComboBoxContentControl.

ShowingPlaceholderText

取得值,這個值表示 ComboBoxContentControl 目前是否顯示預留位置文字。Gets a value that indicates whether the ComboBoxContentControl is currently displaying placeholder text.

Tag

取得或設定要與 ComboBoxContentControl 產生關聯的字串。Gets or sets a string that you want to associate with the ComboBoxContentControl.

Temporary

取得或設定值,這個值指定編輯 ComboBoxContentControl 控制項時,是否會從文件中自動刪除此控制項。Gets or sets a value that specifies whether the ComboBoxContentControl is automatically deleted from the document when the control is edited.

Text

取得或設定 ComboBoxContentControl 中的文字。Gets or sets the text in the ComboBoxContentControl.

Title

取得或設定 ComboBoxContentControl 的標題。Gets or sets the title of the ComboBoxContentControl.

XMLMapping

取得 XMLMapping,代表 ComboBoxContentControl 與自訂 XML 組件中的元素之間的繫結。Gets an XMLMapping that represents the binding between the ComboBoxContentControl and an element in a custom XML part.

方法

Copy()

ComboBoxContentControl 從文件複製到 [剪貼簿]。Copies the ComboBoxContentControl from the document to the Clipboard.

Cut()

從文件移除 ComboBoxContentControl 並將它加入至 [剪貼簿]。Removes the ComboBoxContentControl from the document and adds it to the Clipboard.

Delete(Boolean)

從文件中刪除動態建立的內容控制項,並從文件中的 ControlCollection 將它移除。Deletes a dynamically created content control from the document and removes it from the ControlCollection in the document.

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

顯示 T:Microsoft.Office.Interop.Word.BuildingBlockRange 或字串中的文字,作為 ComboBoxContentControl 中的預留位置文字。Displays text that is in a T:Microsoft.Office.Interop.Word.BuildingBlock, a Range, or a string as the placeholder text in the ComboBoxContentControl.

事件

Added

在內容控制項加入至文件之後發生。Occurs after the content control is added to the document.

(繼承來源 ContentControlBase)
BindingContextChanged

BindingContextContentControlBase 屬性值變更時發生。Occurs when the value of the BindingContext property of the ContentControlBase changes.

(繼承來源 ContentControlBase)
ContentUpdating

如果內容控制項已繫結至自訂 XML 組件,只在 Microsoft Office Word 更新內容控制項中的文字之前發生。Occurs just before Microsoft Office Word updates the text in the content control, if the content control is bound to a custom XML part.

(繼承來源 ContentControlBase)
Deleting

只在內容控制項從文件中刪除之前發生。Occurs just before the content control is deleted from the document.

(繼承來源 ContentControlBase)
Entering

當使用者在內容控制項中按一下或以程式設計方式將游標移至內容控制項時發生。Occurs when the user clicks in the content control, or when the cursor is moved into the content control programmatically.

(繼承來源 ContentControlBase)
Exiting

當使用者在內容控制項外部按一下或以程式設計方式將游標移至內容控制項外部時發生。Occurs when the user clicks outside the content control, or when the cursor is moved outside the content control programmatically.

(繼承來源 ContentControlBase)
StoreUpdating

就在 Microsoft Office Word 更新繫結至內容控制項的自訂 XML 組件資料之前 (也就是內容控制項中的文字變更之後)。Occurs just before Microsoft Office Word updates data in a custom XML part that is bound to the content control (that is, after the text in the content control changes).

(繼承來源 ContentControlBase)
Validated

在成功驗證內容控制項時發生。Occurs when the content control has been successfully validated.

(繼承來源 ContentControlBase)
Validating

驗證內容控制項的內容時發生。Occurs when the contents of the content control are being validated.

(繼承來源 ContentControlBase)

適用於