ControlCollection Class (2007 System)

Represents a collection of controls on a Word document in a Visual Studio Tools for Office solution.

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

Syntax

'Declaration
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public NotInheritable Class ControlCollection _
    Inherits CollectionBase _
    Implements IDisposable
'Usage
Dim instance As ControlCollection
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class ControlCollection : CollectionBase, 
    IDisposable
[PermissionSetAttribute(SecurityAction::Demand, Name = L"FullTrust")]
public ref class ControlCollection sealed : public CollectionBase, 
    IDisposable
public final class ControlCollection extends CollectionBase implements IDisposable

Remarks

Use the methods and properties of the ControlCollection class to manage controls on a Word document. For more information, see Adding Controls to Office Documents at Run Time.

You cannot instantiate this class in your code, because it does not have any public constructors. To get an instance of this class in a document-level project, use the Controls property of the ThisDocument class in your project. To get an instance of this class in a document-level project, use the Controls property of a Document host item that you create programmatically at run time. For more information, see Extending Word Documents and Excel Workbooks in Application-Level Add-ins at Run Time.

The following table shows how to use ControlCollection members to perform some common tasks related to controls on documents.

Task

Action

Add a control to the document.

Use one of the Add<control> methods. For example, to add a Button, use the AddButton method.

Remove a control from the document.

Use the Remove method.

Determine whether a control is in the collection.

Pass the control or its name to the Contains method.

Get the index of a control in the collection.

Pass the control or its name to the IndexOf method.

Get a control from the collection.

Pass the index or name of the control to the Item property in Visual Basic or Indexer in C#.

Inheritance Hierarchy

System.Object
  System.Collections.CollectionBase
    Microsoft.Office.Tools.Word.ControlCollection

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

ControlCollection Members

Microsoft.Office.Tools.Word Namespace

Other Resources

Adding Controls to Office Documents at Run Time

Helper Methods for Host Controls