Share via


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 安全性

請參閱

參考

DocumentBase 類別

Microsoft.Office.Tools.Word 命名空間

其他資源

內容控制項