Share via


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 document, and then removes the Button control.

private void WordControlRemoveAt()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Controls.Button button1 =
        this.Controls.AddButton(0, 0, 56.25F, 17.25F,
        "button1");
    Microsoft.Office.Tools.Word.Controls.MonthCalendar
         monthCalendar1 = this.Controls.AddMonthCalendar(
         0, 20, 75, 15, "monthCalendar1");
    this.Controls.RemoveAt(0);
}
Private Sub WordControlRemoveAt()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim Button1 As Microsoft.Office.Tools.Word.Controls.Button _
        = Me.Controls.AddButton(0, 0, 56.25F, 17.25F, "Button1")
    Dim MonthCalendar1 As Microsoft.Office.Tools.Word. _
        Controls.MonthCalendar = Me.Controls.AddMonthCalendar( _
        0, 20, 75, 15, "MonthCalendar1")
    Me.Controls.RemoveAt(0)
End Sub 

Remarks

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

Applies to