Bahasa

Control.ControlCollection.Remove(Control) Metode

Definisi

Menghapus kontrol yang ditentukan dari kumpulan kontrol.

public:
 virtual void Remove(System::Windows::Forms::Control ^ value);
public virtual void Remove(System.Windows.Forms.Control value);
public virtual void Remove(System.Windows.Forms.Control? value);
abstract member Remove : System.Windows.Forms.Control -> unit
override this.Remove : System.Windows.Forms.Control -> unit
Public Overridable Sub Remove (value As Control)

Parameter

value
Control

untuk Control menghapus dari Control.ControlCollection.

Contoh

Contoh kode berikut menghapus Control dari Control.ControlCollection kelas Panel turunan jika merupakan anggota koleksi. Contoh mengharuskan Anda telah membuat Panel, , Buttondan satu atau beberapa RadioButton kontrol pada Form. RadioButton Kontrol ditambahkan ke Panel kontrol, dan Panel kontrol ditambahkan ke Form. Ketika tombol diklik, tombol radio bernama radioButton2 dihapus dari Control.ControlCollection.

   // Remove the RadioButton control if it exists.
private:
   void removeButton_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      if ( panel1->Controls->Contains( removeButton ) )
      {
         panel1->Controls->Remove( removeButton );
      }
   }
// Remove the RadioButton control if it exists.
private void removeButton_Click(object sender, System.EventArgs e)
{
   if(panel1.Controls.Contains(removeButton))
   {
      panel1.Controls.Remove(removeButton);
   }
}
' Remove the RadioButton control if it exists.
Private Sub RemoveButton_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles RemoveButton.Click
    If Panel1.Controls.Contains(RemoveButton) Then
        Panel1.Controls.Remove(RemoveButton)
    End If
End Sub

Keterangan

Control Ketika dihapus dari koleksi kontrol, semua kontrol berikutnya dipindahkan ke atas satu posisi dalam koleksi.

Anda juga dapat menghapus Control dengan menggunakan RemoveAt metode , atau menghapus semua kontrol dengan menggunakan Clear metode .

Untuk menambahkan objek baru Control ke koleksi, gunakan Add metode atau AddRange .

Catatan Bagi Inheritor

Saat mengambil alih kelas turunan Remove(Control) , pastikan untuk memanggil metode kelas Remove(Control) dasar untuk memastikan bahwa kontrol dihapus dari koleksi.

Berlaku untuk

Lihat juga