Anchor Sides/fr

From Lazarus wiki
Revision as of 12:48, 10 July 2007 by Wile64 (talk | contribs)
Jump to navigationJump to search

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 installer des contrôles pour garder une certaine distance avec d'autres contrôles, ou centrer relativement avec 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é/limite à un côté d'un autre contrôle. Par exemple vous pouvez maintenant ancrer le côté gauche d'un TEdit sur le côté d'un TLabel. Chaque fois que le Label est déplacé ou est remis à la côte le côté gauche de l'éditeur suivra, lequel normalement suivra le 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 avec les propriétés d'espacement de bordure:

Edit1.BorderSpacing.Left:=10;

The same can be done with the method:

Edit1.AnchorToNeighbour(akLeft,10,Label1);

Notes

The Edit1.Left will follow Label1.Left+Label1.Width, not the other way 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

You can anchor the Edit's top side to follow the Label's top side:

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

The same can be done with the method:

Edit1.AnchorParallel(akTop,0,Label1);

Example 3

Centering a Label vertically to an Edit:

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

The same can be done with the method:

Edit1.AnchorVerticalCenterTo(Label1);

Obviously anchoring the bottom side of Edit1 does not make sense when centering.

New property

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

This is not published in the object inspector. You can edit it in the designer via the anchor editor (Menu: View -> View anchor editor, or click on button of 'Anchors' property).

New methods to easily configure common layouts

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