Control.ControlCollection.Remove 方法

从控件集合中移除指定的控件。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Overridable Sub Remove ( _
    value As Control _
)
用法
Dim instance As ControlCollection
Dim value As Control

instance.Remove(value)
public virtual void Remove (
    Control value
)
public:
virtual void Remove (
    Control^ value
)
public void Remove (
    Control value
)
public function Remove (
    value : Control
)

参数

备注

从控件集合中移除一个 Control 后,其后面的所有控件都在集合中上移一个位置。

通过使用 RemoveAt 方法也可以移除 Control,通过使用 Clear 方法可以移除所有控件。

若要向集合中添加新的 Control 对象,请使用 AddAddRange 方法。

给继承者的说明 在派生类中重写 Remove 时,要确保调用基类的 Remove 方法,以保证将控件从集合中移除。

示例

下面的代码示例从派生类 PanelControl.ControlCollection 中移除一个 Control(如果它是该集合的成员)。该示例要求已在 Form 上创建了一个 Panel、一个 Button 以及一个或多个 RadioButton 控件。将 RadioButton 控件添加到 Panel 控件,而将 Panel 控件添加到 Form。单击该按钮时,从 Control.ControlCollection 中移除名为 radioButton2 的单选按钮。

' 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(RadioAddRangeButton) Then
        Panel1.Controls.Remove(RadioAddRangeButton)
    End If
End Sub
// Remove the RadioButton control if it exists.
private 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*/ )
   {
      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)
{
    if (panel1.get_Controls().Contains(removeButton)) {
        panel1.get_Controls().Remove(removeButton);
    }
} //removeButton_Click

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

Control.ControlCollection 类
Control.ControlCollection 成员
System.Windows.Forms 命名空间
RemoveAt
Clear
Add