Control.ControlCollection.Remove(Control) 方法


从控件集合中移除指定的控件。Removes the specified control from the control collection.

 virtual void Remove(System::Windows::Forms::Control ^ value);
public virtual void Remove (System.Windows.Forms.Control value);
abstract member Remove : System.Windows.Forms.Control -> unit
override this.Remove : System.Windows.Forms.Control -> unit
Public Overridable Sub Remove (value As Control)



要从 Control 移除的 Control.ControlCollectionThe Control to remove from the Control.ControlCollection.


下面的代码示例 ControlControl.ControlCollection 派生类的派生类中移除, Panel 前提是它是集合的成员。The following code example removes a Control from the Control.ControlCollection of the derived class Panel if it is a member of the collection. 该示例要求你已在中创建了 Panel 、一个 Button 和一个或多个 RadioButton 控件 FormThe example requires that you have created a Panel, a Button, and one or more RadioButton controls on a Form. 控件 RadioButton 将添加到 Panel 控件,并将该 Panel 控件添加到 FormThe RadioButton controls are added to the Panel control, and the Panel control is added to the Form. 单击该按钮时, radioButton2 会从中删除名为的单选按钮 Control.ControlCollectionWhen the button is clicked, the radio button named radioButton2 is removed from the Control.ControlCollection.

   // Remove the RadioButton control if it exists.
   void removeButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
      if ( panel1->Controls->Contains( removeButton ) )
         panel1->Controls->Remove( removeButton );
// Remove the RadioButton control if it exists.
private void removeButton_Click(object sender, System.EventArgs e)
' Remove the RadioButton control if it exists.
Private Sub RemoveButton_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles RemoveButton.Click
    If Panel1.Controls.Contains(RemoveButton) 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.

你还可以 Control 使用 RemoveAt 方法删除,或使用方法删除所有控件 ClearYou can also remove a Control by using the RemoveAt method, or remove all controls by using the Clear method.

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


Remove(Control) 在派生类中重写时,请确保调用基类的 Remove(Control) 方法,以确保从集合中移除该控件。When overriding Remove(Control) in a derived class, be sure to call the base class's Remove(Control) method to ensure that the control is removed from the collection.