Freigeben über


ControlCollection.RemoveAt(Int32) Method

Definition

Removes the control at the specified index in the ControlCollection instance.

public:
 void RemoveAt(int index);
public void RemoveAt (int index);
abstract member RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)

Parameters

index
Int32

The zero-based index of the control to remove from the ControlCollection instance.

Exceptions

Index is less than zero or index is equal to or greater than count.

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 specified by the index.

private void ExcelControlRemoveAt()
{

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

void button2_Click(object sender, EventArgs e)
{
    this.Controls.RemoveAt(1);
}
Private Sub ExcelControlRemoveAt()

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

    Button2.Text = "Remove"

    AddHandler Button2.Click, AddressOf Button2_Click

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

    Me.Controls.RemoveAt(1)

End Sub

Remarks

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

Applies to