Control.ControlCollection.RemoveAt(Int32) Metod

Definition

Tar bort en kontroll från kontrollsamlingen på den angivna indexerade platsen.

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)

Parametrar

index
Int32

Indexvärdet för att Control ta bort.

Implementeringar

Exempel

I följande kodexempel tas det första Control i den Control.ControlCollection härledda klassen Panel bort om antalet av samlingen är större än noll. Exemplet kräver att du har skapat en Panel, en Buttonoch minst en annan kontroll på en Form. De andra kontrollerna läggs till i Panel kontrollen och Panel kontrollen läggs till i Form. När du klickar på knappen tas den första kontrollen i panelen bort från 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

Kommentarer

När en Control tas bort från kontrollsamlingen flyttas alla efterföljande kontroller upp en position i samlingen.

Du kan också ta bort en Control som du tidigare har lagt till med hjälp Remove av metoderna eller Clear .

Om du vill lägga till nya Control objekt i samlingen använder du Add metoderna eller AddRange .

Gäller för

Se även