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

获取一个表示 Microsoft Office Word 当前实例的 ApplicationGets 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 的父级。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)

适用于