Control.ControlCollection.RemoveAt(Int32) Control.ControlCollection.RemoveAt(Int32) Control.ControlCollection.RemoveAt(Int32) Control.ControlCollection.RemoveAt(Int32) Method


在指定的索引位置从控件集合移除控件。Removes a control from the control collection at the specified indexed location.

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


Int32 Int32 Int32 Int32

要移除的 Control 的索引值。The index value of the Control to remove.



如果集合计数大于零, 则Control下面的Control.ControlCollection代码示例将删除Panel派生类的中的第一个。The following code example removes the first Control in the Control.ControlCollection of the derived class Panel if the count of the collection is greater than zero. 该示例要求你已在中创建Panel了一个Button、一个和至少Form一个其他控件。The example requires that you have created a Panel, a Button, and at least one other control on a Form. 其他控件将添加到Panel控件, Panel并将控件添加到FormThe other controls are added to the Panel control, and the Panel control added to the Form. 单击该按钮时, 将从Control.ControlCollection中移除面板中包含的第一个控件。When the button is clicked, the first control contained in the panel is removed from the Control.ControlCollection.

   // Remove the first control in the collection.
   void removeAtButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
      if ( panel1->Controls->Count > 0 )
         panel1->Controls->RemoveAt( 0 );
// Remove the first control in the collection.
private void removeAtButton_Click(object sender, System.EventArgs e)
   if (panel1.Controls.Count > 0)
  ' Remove the first control in the collection.
  Private Sub RemoveAtButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RemoveAtButton.Click
      If (Panel1.Controls.Count > 0) Then
      End If
  End Sub


Control从控件集合中移除时, 将在集合中的一个位置上移所有后续控件。When a Control is removed from the control collection, all subsequent controls are moved up one position in the collection.

你还可以Remove使用或Control Clear方法删除之前添加的。You can also remove a Control that you previously added by using the Remove or Clear methods.

若要将Control新对象添加到集合, 请Add使用AddRange或方法。To add new Control objects to the collection, use the Add or AddRange methods.