1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| // Utilitaires de positionnement dynamique.
TGraphUtils = Class
// Renvoie, sous forme de TPoint, la taille d'un contrôle.
Function GetSize ( Const Control : TControl ) : TPoint ;
// Convertit à la volée deux coordonnées en un TPoint.
Function Point ( Const X, Y : Integer ) : TPoint ;
// Renvoie l'encadrement d'un contrôle (un pixel autour). Assigner à un BoundsRect.
Function OuterBounds ( Const Control : TControl ) : TRect ;
// Renvoie l'encadrement d'un contrôle (un pixel à l'intérieur). Assigner à un BoundsRect.
Function InnerBounds ( Const Control : TControl ) : TRect ;
// Renvoie le TRect contenant les deux contrôles donnés.
Function UnionBounds ( Const Control1, Control2 : TControl ) : TRect ;
End ;
{ TGraphUtils }
function TGraphUtils.GetSize(const Control: TControl): TPoint;
begin
Result.X:=Control.Width;
Result.Y:=Control.Height;
end;
function TGraphUtils.InnerBounds(const Control: TControl): TRect;
begin
Result:=Control.BoundsRect;
With Result Do
Begin
Inc(Left);
Inc(Top);
Dec(Bottom);
Dec(Right);
End;
end;
function TGraphUtils.OuterBounds(const Control: TControl): TRect;
begin
Result:=Control.BoundsRect;
With Result Do
Begin
Dec(Left);
Dec(Top);
Inc(Bottom);
Inc(Right);
End;
end;
function TGraphUtils.Point(const X, Y: Integer): TPoint;
begin
Result.X:=X;
Result.Y:=Y;
end;
function TGraphUtils.UnionBounds(const Control1, Control2: TControl): TRect;
begin
With Result Do
Begin
Left:=Min(Control1.BoundsRect.Left,Control2.BoundsRect.Left);
Top:=Min(Control1.BoundsRect.Top,Control2.BoundsRect.Top);
Right:=Max(Control1.BoundsRect.Right,Control2.BoundsRect.Right);
Bottom:=Max(Control1.BoundsRect.Bottom,Control2.BoundsRect.Bottom);
End;
end; |
Partager