Control.Parent, propriété
Assembly : System.Windows.Forms (dans system.windows.forms.dll)
/** @property */ public Control get_Parent () /** @property */ public void set_Parent (Control value)
public function get Parent () : Control public function set Parent (value : Control)
Valeur de la propriété
Control qui représente le contrôle parent ou le contrôle conteneur du contrôle.L'attribution à la propriété Parent de la valeur référence Null (Nothing en Visual Basic) supprime le contrôle du Control.ControlCollection de son contrôle parent actuel.
L'exemple de code suivant utilise la propriété Parent et la méthode FindForm pour définir des propriétés sur le contrôle parent d'un bouton et son formulaire.
// This example uses the Parent property and the Find method of Control to set // properties on the parent control of a Button and its Form. The example assumes // that a Button control named button1 is located within a GroupBox control. The // example also assumes that the Click event of the Button control is connected to // the event handler method defined in the example. private void button1_Click(object sender, System.EventArgs e) { // Get the control the Button control is located in. In this case a GroupBox. Control control = button1.Parent; // Set the text and backcolor of the parent control. control.Text = "My Groupbox"; control.BackColor = Color.Blue; // Get the form that the Button control is contained within. Form myForm = button1.FindForm(); // Set the text and color of the form containing the Button. myForm.Text = "The Form of My Control"; myForm.BackColor = Color.Red; }
// This example uses the Parent property and the Find method of Control to
// set properties on the parent control of a Button and its Form. The
// example assumes that a Button control named button1 is located within a
// GroupBox control. The example also assumes that the Click event of the
// Button control is connected to the event handler method defined in the
// example.
private void button1_Click(Object sender, System.EventArgs e)
{
// Get the control the Button control is located in.
// In this case a GroupBox.
Control control = button1.get_Parent();
// Set the text and backcolor of the parent control.
control.set_Text("My Groupbox");
control.set_BackColor(Color.get_Blue());
// Get the form that the Button control is contained within.
Form myForm = button1.FindForm();
// Set the text and color of the form containing the Button.
myForm.set_Text("The Form of My Control");
myForm.set_BackColor(Color.get_Red());
} //button1_Click
- UIPermission pour que toutes les fenêtres obtiennent la valeur de cette propriété. Énumération associée : UIPermissionWindow.AllWindows
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.