Difference between revisions of "Anchor Sides/fr"

From Free Pascal wiki
Jump to navigationJump to search
(New page: {{Anchor Sides}} There are some new properties and methods for automatic layout of controls. You can now setup controls to keep a certain distance to other controls, or center relative to...)
 
m (Fixed syntax highlighting)
 
(47 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{{Anchor Sides}}
 
{{Anchor Sides}}
  
There are some new properties and methods for automatic layout of
+
Il y a quelques nouvelles propriétés et méthodes pour la disposition automatique des contrôles.  
controls.
+
Vous pouvez maintenant paramétrer des contrôles pour conserver une certaine distance à d'autres contrôles,  
You can now setup controls to keep a certain distance to other controls,
+
ou se centrer relativement à d'autres contrôles. Voir ci-dessous pour des exemples.  
or center relative to other controls. See below for examples.
 
  
Each of the four sides of a control (Left, Top, Right, Bottom) can now
+
Chacun des quatre côtés d'un contrôles (Gauche, Haut, Droit, Bas) peut maintenant être ancré/contraint à un côté d'un autre contrôle. Par exemple vous pouvez maintenant ancrer le côté gauche d'un TEdit au coté droit d'un TLabel. Chaque fois que le Label est déplacé ou redimensionné, le côté gauche du contrôle Edit suivra, ce qui se traduit normalement par un déplacement parallèlement au Label.  
be anchored/bound to a side of another control. For example you can now
+
=Exemple 1=
anchor the left side of TEdit to the right side of a TLabel. Everytime
 
the Label is moved or resized the Edit's left side will follow, which
 
normally results in moving the Edit parallel to the Label.
 
 
 
=Example 1=
 
 
  +--------+ +-------+
 
  +--------+ +-------+
 
  | Label1 | | Edit1 |
 
  | Label1 | | Edit1 |
 
  +--------+ |      |
 
  +--------+ |      |
 
             +-------+
 
             +-------+
==In code==
+
==En code==
 +
<syntaxhighlight lang=pascal>
 
  Edit1.AnchorSide[akLeft].Side:=asrRight;
 
  Edit1.AnchorSide[akLeft].Side:=asrRight;
 
  Edit1.AnchorSide[akLeft].Control:=Label1;
 
  Edit1.AnchorSide[akLeft].Control:=Label1;
 
  Edit1.Anchors:=Edit1.Anchors+[akLeft];
 
  Edit1.Anchors:=Edit1.Anchors+[akLeft];
You can define the distance with the BorderSpacing properties:
+
</syntaxhighlight>
Edit1.BorderSpacing.Left:=10;
+
Vous pouvez définir la distance par l'intermédiaire des propriétés d'espacement de bordure:  
The same can be done with the method:
+
<syntaxhighlight lang=pascal> Edit1.BorderSpacing.Left:=10;</syntaxhighlight>
Edit1.AnchorToNeighbour(akLeft,10,Label1);
+
La chose même peut être fait avec la méthode :  
 +
<syntaxhighlight lang=pascal> Edit1.AnchorToNeighbour(akLeft,10,Label1);</syntaxhighlight>
 +
 
 
==Notes==
 
==Notes==
The Edit1.Left will follow Label1.Left+Label1.Width, not the other way
+
Edit1.Left suivra Label1.Left+Label1.Width, pas les autres contours. Cela signifie, que le déplacement du Label1 déplacera Edit1. Mais le déplacement de Edit1 sera défait par la bibliothèque LCL. Si vous ancrez également le côté droit du Label1 au côté gauche de Edit1, vous avez créé un cercle vicieux, et ceci peut résulter comme avec d'autres propriétés de redimensionnement automatique en une boucle infinie. La détection de ces cercles vicieux n'est pas encore implémentée.
around. That means, moving Label1 will move Edit1. But moving Edit1 will
 
be undone by the LCL.
 
If you also anchor the right side of Label1 to the left side of Edit1,
 
you created a circle, and this can result together with some other
 
autosize properties in an infinite loop. Detection of circles is not yet
 
implemented.
 
  
=Example 2=
+
=Exemple 2=
  
You can anchor the Edit's top side to follow the Label's top side:
+
Vous pouvez ancrer le côté supérieur du contrôle Edit pour suivre le côté supérieur du Label:  
 
<pre>
 
<pre>
 
+--------+ +-------+
 
+--------+ +-------+
Line 43: Line 34:
 
           +-------+
 
           +-------+
 
</pre>
 
</pre>
<pre>
+
<syntaxhighlight lang=pascal>
 
Edit1.AnchorSide[akTop].Side:=asrTop;
 
Edit1.AnchorSide[akTop].Side:=asrTop;
 
Edit1.AnchorSide[akTop].Control:=Label1;
 
Edit1.AnchorSide[akTop].Control:=Label1;
 
Edit1.Anchors:=Edit1.Anchors+[akTop];
 
Edit1.Anchors:=Edit1.Anchors+[akTop];
</pre>
+
</syntaxhighlight>
The same can be done with the method:
+
La même chose peut être fait avec la méthode:  
<pre>Edit1.AnchorParallel(akTop,0,Label1);</pre>
+
<syntaxhighlight lang=pascal>Edit1.AnchorParallel(akTop,0,Label1);</syntaxhighlight>
  
=Example 3=
+
=Exemple 3=
  
Centering a Label vertically to an Edit:
+
Centrage du Label verticalement au Edit:
 
<pre>
 
<pre>
 
           +-------+
 
           +-------+
Line 61: Line 52:
 
           +-------+
 
           +-------+
 
</pre>
 
</pre>
<pre>
+
<syntaxhighlight lang=pascal>
 
Edit1.AnchorSide[akTop].Side:=asrCenter;
 
Edit1.AnchorSide[akTop].Side:=asrCenter;
 
Edit1.AnchorSide[akTop].Control:=Label1;
 
Edit1.AnchorSide[akTop].Control:=Label1;
 
Edit1.Anchors:=Edit1.Anchors+[akTop]-[akBottom];
 
Edit1.Anchors:=Edit1.Anchors+[akTop]-[akBottom];
</pre>
+
</syntaxhighlight>
The same can be done with the method:
+
La même chose peut être fait avec la méthode:  
<pre>Edit1.AnchorVerticalCenterTo(Label1);</pre>
+
<syntaxhighlight lang=pascal>Edit1.AnchorVerticalCenterTo(Label1);</syntaxhighlight>
  
Obviously anchoring the bottom side of Edit1 does not make sense when
+
Evidemment, Ancrer le côté inférieur du Edit1 n'a pas de sens avec le centrage.
centering.
 
  
=New property=
+
=Nouvelle propriété=
<pre>property AnchorSide[Kind: TAnchorKind]: TAnchorSide read GetAnchorSide;</pre>
+
<syntaxhighlight lang=pascal>property AnchorSide[Kind: TAnchorKind]: TAnchorSide read GetAnchorSide;</syntaxhighlight>
This is not published in the object inspector. You can edit it in the
+
Cette propriété n'est pas édité dans l'[http://wiki.lazarus.freepascal.org/IDE_Window:_Object_Inspector/fr inspecteur d' objets]. Vous pouvez l'éditer dans le concepteur par l'intermédiaire de l'éditeur d'ancres (Menu: Voir -> Afficher l'[http://wiki.lazarus.freepascal.org/IDE_Window:_Anchor_Editor/fr éditeur d'ancres], ou cliquez sur le bouton de propriété 'Anchors').
designer via the anchor editor (Menu: View -> View anchor editor, or
 
click on button of 'Anchors' property).
 
  
=New methods to easily configure common layouts=
+
=Nouvelles méthodes pour configurer facilement des dispositions (de contrôles) communes=
<pre>
+
<syntaxhighlight lang=pascal>
 
procedure AnchorToNeighbour(Side: TAnchorKind; Space: integer;
 
procedure AnchorToNeighbour(Side: TAnchorKind; Space: integer;
 
                             Sibling: TControl);
 
                             Sibling: TControl);
Line 86: Line 74:
 
procedure AnchorHorizontalCenterTo(Sibling: TControl);
 
procedure AnchorHorizontalCenterTo(Sibling: TControl);
 
procedure AnchorVerticalCenterTo(Sibling: TControl);
 
procedure AnchorVerticalCenterTo(Sibling: TControl);
</pre>
+
</syntaxhighlight>
 +
 
 +
=See also=
 +
 
 +
*[[Autosize / Layout]]
 +
*[[Example: Anchors. How to reliably align dynamically created controls under changing visibility]]

Latest revision as of 08:11, 9 February 2020

Deutsch (de) English (en) français (fr) 日本語 (ja) русский (ru)

Il y a quelques nouvelles propriétés et méthodes pour la disposition automatique des contrôles. Vous pouvez maintenant paramétrer des contrôles pour conserver une certaine distance à d'autres contrôles, ou se centrer relativement à d'autres contrôles. Voir ci-dessous pour des exemples.

Chacun des quatre côtés d'un contrôles (Gauche, Haut, Droit, Bas) peut maintenant être ancré/contraint à un côté d'un autre contrôle. Par exemple vous pouvez maintenant ancrer le côté gauche d'un TEdit au coté droit d'un TLabel. Chaque fois que le Label est déplacé ou redimensionné, le côté gauche du contrôle Edit suivra, ce qui se traduit normalement par un déplacement parallèlement au Label.

Exemple 1

+--------+ +-------+
| Label1 | | Edit1 |
+--------+ |       |
           +-------+

En code

 Edit1.AnchorSide[akLeft].Side:=asrRight;
 Edit1.AnchorSide[akLeft].Control:=Label1;
 Edit1.Anchors:=Edit1.Anchors+[akLeft];

Vous pouvez définir la distance par l'intermédiaire des propriétés d'espacement de bordure:

 Edit1.BorderSpacing.Left:=10;

La chose même peut être fait avec la méthode :

 Edit1.AnchorToNeighbour(akLeft,10,Label1);

Notes

Edit1.Left suivra Label1.Left+Label1.Width, pas les autres contours. Cela signifie, que le déplacement du Label1 déplacera Edit1. Mais le déplacement de Edit1 sera défait par la bibliothèque LCL. Si vous ancrez également le côté droit du Label1 au côté gauche de Edit1, vous avez créé un cercle vicieux, et ceci peut résulter comme avec d'autres propriétés de redimensionnement automatique en une boucle infinie. La détection de ces cercles vicieux n'est pas encore implémentée.

Exemple 2

Vous pouvez ancrer le côté supérieur du contrôle Edit pour suivre le côté supérieur du Label:

+--------+ +-------+
| Label1 | | Edit1 |
+--------+ |       |
           +-------+
Edit1.AnchorSide[akTop].Side:=asrTop;
Edit1.AnchorSide[akTop].Control:=Label1;
Edit1.Anchors:=Edit1.Anchors+[akTop];

La même chose peut être fait avec la méthode:

Edit1.AnchorParallel(akTop,0,Label1);

Exemple 3

Centrage du Label verticalement au Edit:

           +-------+
+--------+ |       |
| Label1 | | Edit1 |
+--------+ |       |
           +-------+
Edit1.AnchorSide[akTop].Side:=asrCenter;
Edit1.AnchorSide[akTop].Control:=Label1;
Edit1.Anchors:=Edit1.Anchors+[akTop]-[akBottom];

La même chose peut être fait avec la méthode:

Edit1.AnchorVerticalCenterTo(Label1);

Evidemment, Ancrer le côté inférieur du Edit1 n'a pas de sens avec le centrage.

Nouvelle propriété

property AnchorSide[Kind: TAnchorKind]: TAnchorSide read GetAnchorSide;

Cette propriété n'est pas édité dans l'inspecteur d' objets. Vous pouvez l'éditer dans le concepteur par l'intermédiaire de l'éditeur d'ancres (Menu: Voir -> Afficher l'éditeur d'ancres, ou cliquez sur le bouton de propriété 'Anchors').

Nouvelles méthodes pour configurer facilement des dispositions (de contrôles) communes

procedure AnchorToNeighbour(Side: TAnchorKind; Space: integer;
                            Sibling: TControl);
procedure AnchorParallel(Side: TAnchorKind; Space: integer;
                         Sibling: TControl);
procedure AnchorHorizontalCenterTo(Sibling: TControl);
procedure AnchorVerticalCenterTo(Sibling: TControl);

See also