Développer Réduire
Ce sujet n'a pas encore été évalué - Évaluez ce sujet

Control.FindForm, méthode

Mise à jour : novembre 2007

Récupère le formulaire sur le lequel se trouve le contrôle.

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

[UIPermissionAttribute(SecurityAction.Demand, Window = UIPermissionWindow.AllWindows)]
public Form FindForm()
/** @attribute UIPermissionAttribute(SecurityAction.Demand, Window = UIPermissionWindow.AllWindows) */
public Form FindForm()
public function FindForm() : Form

Valeur de retour

Type : System.Windows.Forms.Form

Form sur lequel se trouve le contrôle.

La valeur de la propriété Parent du contrôle peut être différente de Form retourné par la méthode FindForm. Par exemple, si un contrôle RadioButton est contenu dans un contrôle GroupBox, et si GroupBox se trouve sur Form, le Parent du contrôle RadioButton est GroupBox et le Parent du contrôle GroupBox est Form.

L'exemple de code suivant recherche le formulaire qui contient le bouton spécifié.

// 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


Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professionnel Édition x64, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

.NET Framework

Pris en charge dans : 3.5, 3.0, 2.0, 1.1, 1.0
Cela vous a-t-il été utile ?
(1500 caractères restants)

Ajouts de la communauté

AJOUTER
© 2013 Microsoft. Tous droits réservés.