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 71 72 73 74 75 76 77
|
unit ex01a;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
Ar1: Array of TRect;
implementation
{$R *.dfm}
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i1: Integer;
bPossible: boolean;
bt1: TButton;
aRect: TRect;
function EntreBornes(X, x1, x2, Y, y1, y2: Integer): boolean;
begin
result := (X > x1) and (X < x2) and (Y > y1) and (Y < y2);
end;
begin
bPossible := true;
bt1 := TButton.Create(self);
bt1.Top := Y;
bt1.Left := X;
aRect.Top := Y;
aRect.Left := X;
aRect.Bottom := Y + Button1.Height;
aRect.Right := X + Button1.Width;
if Length(Ar1) > 0 then
begin
for i1 := low(Ar1) to high(Ar1) do
begin
if EntreBornes(aRect.Left, Ar1[i1].Left, Ar1[i1].Right, aRect.Top,
Ar1[i1].Top, Ar1[i1].Bottom) //
or EntreBornes(aRect.Left, Ar1[i1].Left, Ar1[i1].Right, aRect.Bottom,
Ar1[i1].Top, Ar1[i1].Bottom) //
or EntreBornes(aRect.Right, Ar1[i1].Left, Ar1[i1].Right, aRect.Top,
Ar1[i1].Top, Ar1[i1].Bottom) //
or EntreBornes(aRect.Right, Ar1[i1].Left, Ar1[i1].Right, aRect.Bottom,
Ar1[i1].Top, Ar1[i1].Bottom) then
bPossible := false;
end;
end;
if bPossible then
begin
bt1.Parent := Form1;
SetLength(Ar1, Length(Ar1) + 1);
Ar1[high(Ar1)] := aRect;
end
else
bt1.Free;
end;
end. |
Partager