Dela via


Worksheet.Controls Property (2007 System)

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

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

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public Overridable ReadOnly Property Controls As ControlCollection
'Usage
Dim instance As Worksheet 
Dim value As ControlCollection 

value = instance.Controls
[BrowsableAttribute(false)]
public virtual ControlCollection Controls { get; }
[BrowsableAttribute(false)]
public:
virtual property ControlCollection^ Controls {
    ControlCollection^ get ();
}
public function get Controls () : ControlCollection

Property Value

Type: Microsoft.Office.Tools.Excel.ControlCollection
A ControlCollection that contains all the managed controls on the worksheet.

Remarks

A worksheet in a Visual Studio Tools for Office solution can contain Windows Forms controls and host controls. For more information, see Controls on Office Documents.

To manage the controls on a worksheet at run time, use the methods and properties of the ControlCollection object returned by the Controls property. For more information, see Adding Controls to Office Documents at Run Time

Examples

The following code example uses the Controls property to add a Button to the current worksheet.

This version is for a document-level customization.

Private Sub AddButton()
    Dim button1 As Button = _
        Me.Controls.AddButton(50, 50, 150, 50, "button1")
End Sub 'AddButton
private void AddButton()
{
    Button button1 = this.Controls.AddButton(50, 50, 150, 50, "button1");
}

This version is for an application-level add-in.

Private Sub AddButton()
    Dim vstoWorksheet As Worksheet = _
        CType(Me.Application.ActiveWorkbook.Worksheets(1), Excel.Worksheet) _
        .GetVstoObject()
    Dim button1 As System.Windows.Forms.Button = _
        vstoWorksheet.Controls.AddButton(50, 50, 150, 50, "button1")
End Sub 'AddButton
private void AddButton()
{
    Worksheet vstoWorksheet = ((Excel.Worksheet)
        this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
    System.Windows.Forms.Button button1 = 
        vstoWorksheet.Controls.AddButton(50, 50, 150, 50, "button1");
}

.NET Framework Security

See Also

Reference

Worksheet Class

Worksheet Members

Microsoft.Office.Tools.Excel Namespace

Change History

Date

History

Reason

July 2008

Added a version of the code example for an application-level add-in.

SP1 feature change.