Freigeben über


ControlCollection.Remove Method (String)

Removes the control with the specified name from the ControlCollection instance.

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

Syntax

'Declaration
Function Remove ( _
    name As String _
) As Boolean
bool Remove(
    string name
)

Parameters

Return Value

Type: System.Boolean

Remarks

Controls that were added at design time cannot be removed from the ControlCollection instance. You can only use the Remove method to remove controls added at run time.

Examples

The following code example adds a Button control and a MonthCalendar control to the worksheet. When the button is clicked, the code removes the MonthCalendar control.

Private Sub ExcelControlRemove()

    Dim Button1 As Microsoft.Office.Tools.Excel. _
        Controls.Button = Me.Controls.AddButton( _
        0, 0, 56.25, 17.25, "Button1")
    Dim MonthCalendar1 As Microsoft.Office.Tools. _
        Excel.Controls.MonthCalendar = Me.Controls. _
        AddMonthCalendar(0, 20, 75, 15, "MonthCalendar1")

    Button1.Text = "Remove" 

    AddHandler Button1.Click, AddressOf Button1_Click

End Sub 
Private Sub Button1_Click(ByVal sender As Object, ByVal e As _
    EventArgs)

    Me.Controls.Remove("MonthCalendar1")

End Sub
private void ExcelControlRemove()
{

    Microsoft.Office.Tools.Excel.Controls.Button button1 =
        this.Controls.AddButton(0, 0, 56.25, 17.25,
        "button1");
    Microsoft.Office.Tools.Excel.Controls.MonthCalendar
         monthCalendar1 = this.Controls.AddMonthCalendar(
         0, 20, 75, 15, "monthCalendar1");
    button1.Text = "Remove";
    button1.Click += new EventHandler(button1_Click);

}

void button1_Click(object sender, EventArgs e)
{
    this.Controls.Remove("monthCalendar1");
}

.NET Framework Security

See Also

Reference

ControlCollection Interface

Remove Overload

Microsoft.Office.Tools.Excel Namespace