Share via


Document.ContentControls Property (2007 System)

Gets the collection of all the content controls in the document.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public ReadOnly Property ContentControls As ContentControls
'Usage
Dim instance As Document 
Dim value As ContentControls 

value = instance.ContentControls
[BrowsableAttribute(false)]
public ContentControls ContentControls { get; }
[BrowsableAttribute(false)]
public:
property ContentControls^ ContentControls {
    ContentControls^ get ();
}
public function get ContentControls () : ContentControls

Property Value

Type: ContentControls
A ContentControls collection that contains all the content controls in the document.

Remarks

This property returns the collection of native content controls in the document (that is, the ContentControl objects in the document).

To access the Visual Studio Tools for Office content controls in the document, use the Controls property.

For more information about Visual Studio Tools for Office content controls, see Content Controls.

Examples

The following code example adds a plain text control to the first paragraph and sets the control title. The code then iterates through all content controls in the document and shows a message box that displays the type and title of each content control.

This example is for a document-level customization.

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 Security

See Also

Reference

Document Class

Document Members

Microsoft.Office.Tools.Word Namespace

Other Resources

Content Controls