Aracılığıyla paylaş


DocumentBase.Controls Property

Definition

Gets the collection of managed controls that are contained on the document.

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

Property Value

A ControlCollection that contains all the managed controls on the document.

Examples

The following code example adds text to the first paragraph and creates a Bookmark control that encompasses the paragraph. The code then shows a message box that displays the total number of controls on the document. To use this example, run it from the ThisDocument class in a document-level project.

private void DocumentControls()
{
    this.Paragraphs[1].Range.InsertParagraphAfter();
    this.Paragraphs[1].Range.Text = "This is some sample text.";
    this.Controls.AddBookmark(this.Paragraphs[1].Range, "Bookmark1");
    MessageBox.Show("Total number of controls: " +
        this.Controls.Count.ToString());
}
Private Sub DocumentControls()
    Me.Paragraphs(1).Range.InsertParagraphAfter()
    Me.Paragraphs(1).Range.Text = "This is some sample text."
    Me.Controls.AddBookmark(Me.Paragraphs(1).Range, "Bookmark1")
    MessageBox.Show("Total number of controls: " & Me.Controls.Count.ToString())
End Sub

Remarks

A document in an Office solution can contain Windows Forms controls and host controls. For more information, see Controls on Office Documents.

Applies to