Compartir a través de


DocumentBase.ContentControls Property

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

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

Syntax

'Declaration
Public ReadOnly Property ContentControls As ContentControls
public ContentControls ContentControls { get; }

Property Value

Type: Microsoft.Office.Interop.Word.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 Microsoft.Office.Interop.Word.ContentControl objects in the document).

To access the extended content controls in the document, use the Controls property.

For more information about extended 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. To use this example, run it from the ThisDocument class in a document-level project.

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

DocumentBase Class

Microsoft.Office.Tools.Word Namespace

Other Resources

Content Controls