共用方式為


WorksheetBase.Controls Property

Definition

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

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

Property Value

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

Examples

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

This example is for a document-level customization.

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

Remarks

A worksheet 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 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

Applies to