Megosztás a következőn keresztül:


Worksheet.Controls Property

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

Namespace:  Microsoft.Office.Tools.Excel
Assemblies:   Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)
  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
ReadOnly Property Controls As ControlCollection
ControlCollection Controls { get; }

Property Value

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

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

Examples

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

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

Private Sub AddButton()

    Dim NativeWorksheet As Microsoft.Office.Interop.Excel.Worksheet =
        Globals.ThisAddIn.Application.ActiveWorksheet("Sheet1")
    Dim vstoWorksheet As Microsoft.Office.Tools.Excel.Worksheet =
        Globals.Factory.GetVstoObject(NativeWorksheet)

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

.NET Framework Security

See Also

Reference

Worksheet Interface

Microsoft.Office.Tools.Excel Namespace