本文為機器翻譯文章。如需檢視英文版,請選取 [原文] 核取方塊。您也可以將滑鼠指標移到文字上,即可在快顯視窗顯示英文原文。
譯文
原文

Document.Controls 屬性

 

取得包含在文件上的受管理控制項集合。

命名空間:   Microsoft.Office.Tools.Word
組件:  Microsoft.Office.Tools.Word (於 Microsoft.Office.Tools.Word.dll)

ControlCollection Controls { get; }

屬性值

Type: Microsoft.Office.Tools.Word.ControlCollection

ControlCollection,包含文件上的所有受管理控制項。

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

To manage the controls on a document at run time, use the methods and properties of the T:Microsoft.Office.Tools.Word.ControlCollection object returned by the P:Microsoft.Office.Tools.Word.Document.Controls property. For more information, see Adding Controls to Office Documents at Run Time.

The following code example adds text to the first paragraph and creates a T:Microsoft.Office.Tools.Word.Bookmark control that encompasses the paragraph. The code then shows a message box that displays the total number of controls on the document. This example is for an application-level add-in.

private void DocumentControls()
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.Paragraphs[1].Range.InsertParagraphAfter();
    vstoDoc.Paragraphs[1].Range.Text = "This is some sample text.";
    vstoDoc.Controls.AddBookmark(vstoDoc.Paragraphs[1].Range, "Bookmark1");
    System.Windows.Forms.MessageBox.Show("Total number of controls: " +
        vstoDoc.Controls.Count.ToString());
}
回到頁首
顯示: