Compartir a través de


DocumentBase.ContentControls Property

Definition

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

public:
 property Microsoft::Office::Interop::Word::ContentControls ^ ContentControls { Microsoft::Office::Interop::Word::ContentControls ^ get(); };
public Microsoft.Office.Interop.Word.ContentControls ContentControls { get; }
member this.ContentControls : Microsoft.Office.Interop.Word.ContentControls
Public ReadOnly Property ContentControls As ContentControls

Property Value

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

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 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

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.

Applies to