DocumentBase.ContentControls 属性
获取文档中所有内容控件的集合。
命名空间: Microsoft.Office.Tools.Word
程序集: Microsoft.Office.Tools.Word.v4.0.Utilities(在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)
语法
声明
Public ReadOnly Property ContentControls As ContentControls
public ContentControls ContentControls { get; }
属性值
类型:Microsoft.Office.Interop.Word.ContentControls
包含文档中的所有内容控件的 ContentControls 集合。
备注
此属性返回文档中的本机内容控件(即文档中的 Microsoft.Office.Interop.Word.ContentControl 对象)的集合。
若要访问文档中的扩展内容控件,请使用 Controls 属性。
有关扩展内容控件的更多信息,请参见内容控件。
示例
下面的代码示例将向第一个段落中添加一个纯文本控件并设置控件标题。 随后,该代码将循环访问文档中的所有内容控件,然后显示一个消息框并在其中显示每个内容控件的类型和标题。 若要使用此示例,请从文档级项目内的 ThisDocument 类中运行此示例。
Private Sub IterateContentControls()
Dim textControl1 As Word.ContentControl = _
Me.ContentControls.Add( _
Word.WdContentControlType.wdContentControlText, _
Me.Paragraphs(1).Range)
textControl1.Title = "First Name"
For Each cc As Word.ContentControl In Me.ContentControls
MessageBox.Show("Content control type: " + cc.Type.ToString() _
+ ", title: " + cc.Title)
Next
End Sub
private void IterateContentControls()
{
object _range = this.Paragraphs[1].Range;
Word.ContentControl textControl1 = this.ContentControls.Add(
Word.WdContentControlType.wdContentControlText,
ref _range);
textControl1.Title = "First Name";
foreach (Word.ContentControl cc in this.ContentControls)
{
MessageBox.Show("Content control type: "
+ cc.Type.ToString() + ", title: " + cc.Title);
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
请参见
参考
Microsoft.Office.Tools.Word 命名空间