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 のインデックス値。

実装

次のコード例では、コレクションの数が 0 より大きい場合にPanel派生クラスのControl.ControlCollectionの最初のControlを削除します。 この例では、FormPanelButton、および他のコントロールを少なくとも 1 つ作成している必要があります。 他のコントロールは 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がコントロール コレクションから削除されると、後続のすべてのコントロールがコレクション内の 1 つ上の位置に移動します。

ControlメソッドまたはRemoveメソッドを使用して、以前に追加したClearを削除することもできます。

新しい Control オブジェクトをコレクションに追加するには、 Add または AddRange メソッドを使用します。

適用対象

こちらもご覧ください