更新: 2008 年 7 月
获取 DropDownListContentControl 所显示的项的集合。
命名空间: Microsoft.Office.Tools.Word
程序集: Microsoft.Office.Tools.Word.v9.0(在 Microsoft.Office.Tools.Word.v9.0.dll 中)
语法
声明
<TypeConverterAttribute("Microsoft.VisualStudio.OfficeTools.Word2007.Design.DropDownListConverter, Microsoft.VisualStudio.Tools.Office.Designer.Office2007, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")> _
Public ReadOnly Property DropDownListEntries As ContentControlListEntries
用法
Dim instance As DropDownListContentControl
Dim value As ContentControlListEntries
value = instance.DropDownListEntries
[TypeConverterAttribute("Microsoft.VisualStudio.OfficeTools.Word2007.Design.DropDownListConverter, Microsoft.VisualStudio.Tools.Office.Designer.Office2007, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public ContentControlListEntries DropDownListEntries { get; }
属性值
类型:Microsoft.Office.Interop.Word.ContentControlListEntries
一个 ContentControlListEntries 对象,其中包含 DropDownListContentControl 显示的项。
备注
在将 DropDownListContentControl 添加到文档时默认不包含任何项。若要添加项,请使用 DropDownListEntries 属性的 Add 方法。
示例
下面的代码示例会在文档开头添加一个新的 DropDownListContentControl。该示例使用 DropDownListEntries 属性向用户可在控件中选择的项列表中添加一些日期的名称。
此版本针对的是文档级自定义项。若要使用此代码,请将其粘贴到项目内的 ThisDocument 类中,然后从 ThisDocument_Startup 方法中调用 AddDropDownListControlAtSelection 方法。
Dim dropDownListControl1 As Microsoft.Office.Tools.Word.DropDownListContentControl
Private Sub AddDropDownListControlAtSelection()
Me.Paragraphs(1).Range.InsertParagraphBefore()
Me.Paragraphs(1).Range.Select()
dropDownListControl1 = Me.Controls.AddDropDownListContentControl("dropDownListControl1")
With dropDownListControl1
.DropDownListEntries.Add("Monday", "Monday", 0)
.DropDownListEntries.Add("Tuesday", "Tuesday", 1)
.DropDownListEntries.Add("Wednesday", "Wednesday", 2)
.PlaceholderText = "Choose a day"
End With
End Sub
private Microsoft.Office.Tools.Word.DropDownListContentControl dropDownListControl1;
private void AddDropDownListControlAtSelection()
{
this.Paragraphs[1].Range.InsertParagraphBefore();
this.Paragraphs[1].Range.Select();
dropDownListControl1 = this.Controls.AddDropDownListContentControl("dropDownListControl1");
dropDownListControl1.DropDownListEntries.Add("Monday", "Monday", 0);
dropDownListControl1.DropDownListEntries.Add("Tuesday", "Tuesday", 1);
dropDownListControl1.DropDownListEntries.Add("Wednesday", "Wednesday", 2);
dropDownListControl1.PlaceholderText = "Choose a day";
}
此版本针对的是应用程序级外接程序。若要使用此代码,请将其粘贴到项目内的 ThisAddIn 类中,然后从 ThisAddIn_Startup 方法中调用 AddDropDownListControlAtSelection 方法。
Dim dropDownListControl1 As Microsoft.Office.Tools.Word.DropDownListContentControl
Private Sub AddDropDownListControlAtSelection()
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()
dropDownListControl1 = vstoDoc.Controls.AddDropDownListContentControl("dropDownListControl1")
With dropDownListControl1
.DropDownListEntries.Add("Monday", "Monday", 0)
.DropDownListEntries.Add("Tuesday", "Tuesday", 1)
.DropDownListEntries.Add("Wednesday", "Wednesday", 2)
.PlaceholderText = "Choose a day"
End With
End Sub
private Microsoft.Office.Tools.Word.DropDownListContentControl dropDownListControl1;
private void AddDropDownListControlAtSelection()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = this.Application.ActiveDocument.GetVstoObject();
vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
vstoDoc.Paragraphs[1].Range.Select();
dropDownListControl1 = vstoDoc.Controls.AddDropDownListContentControl("dropDownListControl1");
dropDownListControl1.DropDownListEntries.Add("Monday", "Monday", 0);
dropDownListControl1.DropDownListEntries.Add("Tuesday", "Tuesday", 1);
dropDownListControl1.DropDownListEntries.Add("Wednesday", "Wednesday", 2);
dropDownListControl1.PlaceholderText = "Choose a day";
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
另请参见
参考
Microsoft.Office.Tools.Word 命名空间
修订记录
日期 |
修订记录 |
原因 |
---|---|---|
2008 年 7 月 |
添加了一个针对应用程序级外接程序的代码示例版本。 |
SP1 功能更改。 |