Control.ControlCollection.RemoveAt 方法

在指定的索引位置从控件集合移除控件。

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

语法

声明
Public Sub RemoveAt ( _
    index As Integer _
)
用法
Dim instance As ControlCollection
Dim index As Integer

instance.RemoveAt(index)
public void RemoveAt (
    int index
)
public:
virtual void RemoveAt (
    int index
) sealed
public final void RemoveAt (
    int index
)
public final function RemoveAt (
    index : int
)

参数

  • index
    要移除的 Control 的索引值。

备注

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

还可使用 RemoveClear 方法,移除先前添加的 Control

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

示例

下面的代码示例移除派生类 PanelControl.ControlCollection 中的第一个 Control(如果该集合的计数大于零)。该示例要求已在 Form 上创建了一个 Panel、一个 Button 以及至少一个其他控件。将其他控件添加到 Panel 控件,而将 Panel 控件添加到 Form。单击该按钮后,面板中包含的第一个控件将被从 Control.ControlCollection 中移除。

' 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
        Panel1.Controls.RemoveAt(0)
    End If
End Sub
// Remove the first control in the collection.
private 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 )
      {
         panel1->Controls->RemoveAt( 0 );
      }
   }
// Remove the first control in the collection.
private void removeAtButton_Click(Object sender, System.EventArgs e)
{
    if (panel1.get_Controls().get_Count() > 0) {
        panel1.get_Controls().RemoveAt(0);
    }
} //removeAtButton_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 命名空间
Remove
Clear
Add