LayoutEngine.Layout(Object, LayoutEventArgs) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Demande que le moteur de disposition effectue une opération de disposition.
public:
virtual bool Layout(System::Object ^ container, System::Windows::Forms::LayoutEventArgs ^ layoutEventArgs);
public virtual bool Layout(object container, System.Windows.Forms.LayoutEventArgs layoutEventArgs);
abstract member Layout : obj * System.Windows.Forms.LayoutEventArgs -> bool
override this.Layout : obj * System.Windows.Forms.LayoutEventArgs -> bool
Public Overridable Function Layout (container As Object, layoutEventArgs As LayoutEventArgs) As Boolean
Paramètres
- container
- Object
Conteneur sur lequel le moteur de disposition fonctionnera.
- layoutEventArgs
- LayoutEventArgs
Argument d’événement d’un Layout événement.
Retours
true si la disposition doit être effectuée à nouveau par le parent de container; sinon, false.
Exceptions
container n’est pas un type sur lequel LayoutEngine effectuer la disposition.
Exemples
L’exemple de code suivant illustre l’utilisation de la Layout méthode pour implémenter le comportement de disposition personnalisé. Cet exemple de code fait partie d’un exemple plus grand fourni pour la LayoutEngine classe.
public:
virtual bool Layout(Object^ container,
LayoutEventArgs^ layoutEventArgs) override
{
Control^ parent = nullptr;
try
{
parent = (Control ^) container;
}
catch (InvalidCastException^ ex)
{
throw gcnew ArgumentException(
"The parameter 'container' must be a control", "container", ex);
}
// Use DisplayRectangle so that parent.Padding is honored.
Rectangle parentDisplayRectangle = parent->DisplayRectangle;
Point nextControlLocation = parentDisplayRectangle.Location;
for each (Control^ currentControl in parent->Controls)
{
// Only apply layout to visible controls.
if (!currentControl->Visible)
{
continue;
}
// Respect the margin of the control:
// shift over the left and the top.
nextControlLocation.Offset(currentControl->Margin.Left,
currentControl->Margin.Top);
// Set the location of the control.
currentControl->Location = nextControlLocation;
// Set the autosized controls to their
// autosized heights.
if (currentControl->AutoSize)
{
currentControl->Size = currentControl->GetPreferredSize(
parentDisplayRectangle.Size);
}
// Move X back to the display rectangle origin.
nextControlLocation.X = parentDisplayRectangle.X;
// Increment Y by the height of the control
// and the bottom margin.
nextControlLocation.Y += currentControl->Height +
currentControl->Margin.Bottom;
}
// Optional: Return whether or not the container's
// parent should perform layout as a result of this
// layout. Some layout engines return the value of
// the container's AutoSize property.
return false;
}
public override bool Layout(
object container,
LayoutEventArgs layoutEventArgs)
{
Control parent = container as Control;
// Use DisplayRectangle so that parent.Padding is honored.
Rectangle parentDisplayRectangle = parent.DisplayRectangle;
Point nextControlLocation = parentDisplayRectangle.Location;
foreach (Control c in parent.Controls)
{
// Only apply layout to visible controls.
if (!c.Visible)
{
continue;
}
// Respect the margin of the control:
// shift over the left and the top.
nextControlLocation.Offset(c.Margin.Left, c.Margin.Top);
// Set the location of the control.
c.Location = nextControlLocation;
// Set the autosized controls to their
// autosized heights.
if (c.AutoSize)
{
c.Size = c.GetPreferredSize(parentDisplayRectangle.Size);
}
// Move X back to the display rectangle origin.
nextControlLocation.X = parentDisplayRectangle.X;
// Increment Y by the height of the control
// and the bottom margin.
nextControlLocation.Y += c.Height + c.Margin.Bottom;
}
// Optional: Return whether or not the container's
// parent should perform layout as a result of this
// layout. Some layout engines return the value of
// the container's AutoSize property.
return false;
}
Public Overrides Function Layout( _
ByVal container As Object, _
ByVal layoutEventArgs As LayoutEventArgs) As Boolean
Dim parent As Control = container
' Use DisplayRectangle so that parent.Padding is honored.
Dim parentDisplayRectangle As Rectangle = parent.DisplayRectangle
Dim nextControlLocation As Point = parentDisplayRectangle.Location
Dim c As Control
For Each c In parent.Controls
' Only apply layout to visible controls.
If c.Visible <> True Then
Continue For
End If
' Respect the margin of the control:
' shift over the left and the top.
nextControlLocation.Offset(c.Margin.Left, c.Margin.Top)
' Set the location of the control.
c.Location = nextControlLocation
' Set the autosized controls to their
' autosized heights.
If c.AutoSize Then
c.Size = c.GetPreferredSize(parentDisplayRectangle.Size)
End If
' Move X back to the display rectangle origin.
nextControlLocation.X = parentDisplayRectangle.X
' Increment Y by the height of the control
' and the bottom margin.
nextControlLocation.Y += c.Height + c.Margin.Bottom
Next c
' Optional: Return whether or not the container's
' parent should perform layout as a result of this
' layout. Some layout engines return the value of
' the container's AutoSize property.
Return False
End Function
Remarques
Cette méthode est appelée lorsque le moteur de disposition doit effectuer une opération de disposition sur le container paramètre. Vous pouvez vérifier la valeur du , AffectedComponentet AffectedControl les propriétés sur layoutEventArgs lesquelles décider si une opération de AffectedPropertydisposition est nécessaire.
Notes pour les héritiers
Remplacez la Layout(Object, LayoutEventArgs) méthode pour fournir votre comportement de disposition personnalisé.
Lors de la disposition du contenu du container paramètre, veillez à vérifier la Visible propriété de chaque contrôle enfant.
Retournez true si votre logique de moteur de disposition détermine que la disposition doit être effectuée à nouveau par le parent du conteneur. Cela peut se produire, par exemple, lorsque le moteur de disposition redimensionne les contrôles enfants et détermine que le conteneur doit être augmenté de taille pour prendre en charge la nouvelle disposition.