Control.ControlCollection.RemoveAt(Int32) 方法

定義

從控制項集合中指定的索引位置移除控制項。

public:
 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)

參數

index
Int32

要移除之 Control 的索引值。

實作

範例

如果集合的計數大於零,下列程式碼範例會移除衍生類別 Panel 中的 Control.ControlCollection 第一 Control 個 。 此範例會要求您已在 上 Form 建立 Panel 、、 Button 和 至少一個其他控制項。 其他控制項會新增至 Panel 控制項,以及 Panel 加入至 的 Form 控制項。 按一下按鈕時,面板中包含的第一個控制項會從 Control.ControlCollection 中移除。

   // 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 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

備註

Control從控制項集合中移除 時,所有後續控制項都會向上移動集合中的一個位置。

您也可以使用 或 Clear 方法移除 Control 您先前新增的 Remove

若要將新 Control 物件加入至集合,請使用 AddAddRange 方法。

適用於

另請參閱