Cet article a fait l’objet d’une traduction automatique. Pour afficher l’article en anglais, activez la case d’option Anglais. Vous pouvez également afficher le texte anglais dans une fenêtre contextuelle en faisant glisser le pointeur de la souris sur le texte traduit.
Traduction
Anglais

Control.Controls propriété

 

Date de publication : novembre 2016

Obtient la collection de contrôles contenus dans le contrôle.

Espace de noms:   System.Windows.Forms
Assembly:  System.Windows.Forms (dans System.Windows.Forms.dll)

[BrowsableAttribute(false)]
public Control.ControlCollection Controls { get; }

Valeur de propriété

Type: System.Windows.Forms.Control.ControlCollection

Control.ControlCollection représentant la collection de contrôles contenus dans le contrôle.

A T:System.Windows.Forms.Control can act as a parent to a collection of controls. For example, when several controls are added to a T:System.Windows.Forms.Form, each of the controls is a member of the T:System.Windows.Forms.Control.ControlCollection assigned to the P:System.Windows.Forms.Control.Controls property of the form, which is derived from the T:System.Windows.Forms.Control class.

You can manipulate the controls in the T:System.Windows.Forms.Control.ControlCollection assigned to the P:System.Windows.Forms.Control.Controls property by using the methods available in the T:System.Windows.Forms.Control.ControlCollection class.

When adding several controls to a parent control, it is recommended that you call the M:System.Windows.Forms.Control.SuspendLayout method before initializing the controls to be added. After adding the controls to the parent control, call the M:System.Windows.Forms.Control.ResumeLayout method. Doing so will increase the performance of applications with many controls.

Use the P:System.Windows.Forms.Control.Controls property to iterate through all controls of a form, including nested controls. Use the M:System.Windows.Forms.Control.GetNextControl(System.Windows.Forms.Control,System.Boolean) method to retrieve the previous or next child control in the tab order. Use the P:System.Windows.Forms.ContainerControl.ActiveControl property to get or set the active control of a container control.

The following code example removes a T:System.Windows.Forms.Control from the T:System.Windows.Forms.Control.ControlCollection of the derived class T:System.Windows.Forms.Panel if it is a member of the collection. The example requires that you have created a T:System.Windows.Forms.Panel, a T:System.Windows.Forms.Button, and at least one T:System.Windows.Forms.RadioButton control on a T:System.Windows.Forms.Form. The T:System.Windows.Forms.RadioButton control(s) are added to the T:System.Windows.Forms.Panel control, and the T:System.Windows.Forms.Panel control added to the T:System.Windows.Forms.Form. When the button is clicked, the radio button named removeButton is removed from the T:System.Windows.Forms.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);
   }
}

.NET Framework
Disponible depuis 1.1
Retour au début
Afficher: