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 Control.ControlCollection 클래스를 제거합니다. 이 예제에서는 에 대해 하나 이상의 다른 컨트롤FormButton만들어야 Panel합니다. 다른 컨트롤이 컨트롤에 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 메서드를 사용하여 Remove 이전에 추가한 Control 항목을 제거할 수도 있습니다.

새로 추가 하려면 Control 컬렉션에 개체를 사용 합니다 Add 또는 AddRange 메서드.

적용 대상

추가 정보