Share via


DocumentBase.Controls 屬性

取得文件中包含的 Managed 控制項集合。

命名空間:  Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word.v4.0.Utilities (在 Microsoft.Office.Tools.Word.v4.0.Utilities.dll 中)

語法

'宣告
Public ReadOnly Property Controls As ControlCollection
public ControlCollection Controls { get; }

屬性值

型別:Microsoft.Office.Tools.Word.ControlCollection
ControlCollection ,包含文件全部的 Managed 控制項。

備註

Office 方案中的文件可以包含 Windows Form 控制項和主控制項。 如需詳細資訊,請參閱Office 文件上的控制項

範例

下列程式碼範例會將文字加入至第一個段落,然後建立內含該段落的 Bookmark 控制項。 然後程式碼會顯示訊息方塊,說明文件上的控制項總數。 若要使用這個範例,請在文件層級專案中的 ThisDocument 類別執行。

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
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());
}

.NET Framework 安全性

請參閱

參考

DocumentBase 類別

Microsoft.Office.Tools.Word 命名空間

其他資源

Office 文件上的控制項