ControlCollection.RemoveAt Method (Int32)

 

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

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

void RemoveAt(
	int index
)

Parameters

index
Type: System.Int32

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

Exception Condition
ArgumentOutOfRangeException

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

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.

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);
}
Return to top
Show: