Freigeben über


ControlCollection.Remove Method

Definition

Overloads

Remove(String)

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

Remove(Object)

Removes the specified control from the ControlCollection instance.

Remove(String)

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

public:
 bool Remove(System::String ^ name);
public bool Remove (string name);
abstract member Remove : string -> bool
Public Function Remove (name As String) As Boolean

Parameters

name
String

The name of the control to be removed from the ControlCollection instance.

Returns

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 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");
}
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

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.

Applies to

Remove(Object)

Removes the specified control from the ControlCollection instance.

public:
 void Remove(System::Object ^ control);
public void Remove (object control);
abstract member Remove : obj -> unit
Public Sub Remove (control As Object)

Parameters

control
Object

The control to be removed from the ControlCollection instance.

Remarks

Controls that are 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.

Applies to