Mise à jour : novembre 2007
Se produit lorsqu'un contrôle doit repositionner ses contrôles enfants.
Espace de noms :
System.Windows.Forms Assembly :
System.Windows.Forms (dans System.Windows.Forms.dll)
Visual Basic (Déclaration)
Public Event Layout As LayoutEventHandler
Visual Basic (Utilisation)
Dim instance As Control
Dim handler As LayoutEventHandler
AddHandler instance.Layout, handler
public event LayoutEventHandler Layout
public:
event LayoutEventHandler^ Layout {
void add (LayoutEventHandler^ value);
void remove (LayoutEventHandler^ value);
}
/** @event */
public void add_Layout (LayoutEventHandler value)
/** @event */
public void remove_Layout (LayoutEventHandler value)
JScript ne prend pas en charge les événements.
L'événement Layout se produit lorsque des contrôles enfants sont ajoutés ou supprimés, lorsque les limites du contrôle changent et lors d'autres modifications pouvant modifier la présentation du contrôle. L'événement Layout peut être supprimé en utilisant les méthodes SuspendLayout et ResumeLayout. L'interruption de la logique de présentation permet l'exécution de plusieurs actions sur un contrôle sans revoir la présentation à chaque modification. Par exemple, si vous redimensionnez et déplacez un contrôle, chaque opération déclencherait un événement Layout.
Pour plus d'informations sur la gestion d'événements, consultez Consommation d'événements.
L'exemple de code suivant centre Form à l'écran dans l'événement Layout. Cela maintiendra le formulaire centré pendant que l'utilisateur le redimensionne. Cet exemple requiert que vous ayez créé un contrôle Form.
Private Sub MyForm_Layout(ByVal sender As Object, _
ByVal e As System.Windows.Forms.LayoutEventArgs) Handles MyBase.Layout
' Center the Form on the user's screen everytime it requires a Layout.
Me.SetBounds((System.Windows.Forms.Screen.GetBounds(Me).Width / 2) - (Me.Width / 2), _
(System.Windows.Forms.Screen.GetBounds(Me).Height / 2) - (Me.Height / 2), _
Me.Width, Me.Height, System.Windows.Forms.BoundsSpecified.Location)
End Sub
private void MyForm_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
{
// Center the Form on the user's screen everytime it requires a Layout.
this.SetBounds((Screen.GetBounds(this).Width/2) - (this.Width/2),
(Screen.GetBounds(this).Height/2) - (this.Height/2),
this.Width, this.Height, BoundsSpecified.Location);
}
private:
void MyForm_Layout( Object^ /*sender*/, System::Windows::Forms::LayoutEventArgs^ /*e*/ )
{
// Center the Form on the user's screen everytime it requires a Layout.
this->SetBounds( (Screen::GetBounds( this ).Width / 2) - (this->Width / 2), (Screen::GetBounds( this ).Height / 2) - (this->Height / 2), this->Width, this->Height, BoundsSpecified::Location );
}
private void MyForm_Layout(Object sender,
System.Windows.Forms.LayoutEventArgs e)
{
// Center the Form on the user's screen everytime it requires a Layout.
this.SetBounds(Screen.GetBounds(this).get_Width()
/ 2 - this.get_Width() / 2, Screen.GetBounds(this).get_Height()
/ 2 - this.get_Height() / 2, this.get_Width(), this.get_Height(),
BoundsSpecified.Location);
} //MyForm_Layout
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
Référence
Layout