DocumentBase.ContentControls 属性

定义

获取文档中的所有内容控件集合。

public Microsoft.Office.Interop.Word.ContentControls ContentControls { get; }

属性值

ContentControls

一个 ContentControls 集合,包含文档中的所有内容控件。

示例

下面的代码示例将一个纯文本控件添加到第一个段落,并设置控件标题。 然后,该代码将循环访问文档中的所有内容控件并显示一个消息框,其中显示了每个内容控件的类型和标题。 若要使用此示例,请在 ThisDocument 文档级项目的类中运行它。

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

注解

此属性返回文档(即文档中的对象)中的本机内容控件的集合 Microsoft.Office.Interop.Word.ContentControl

若要访问文档中的扩展内容控件,请使用 Controls 属性。

有关扩展的内容控件的详细信息,请参阅内容控件

适用于