uses LCLType, LCLIntf;
type
TData = record
FX, FY, FR: Integer;
FRgn: HRGN;
end;
var
Data: array of TData;
procedure TForm1.FormCreate(Sender: TObject);
begin
//just some random circles
SetLength(Data, 3);
with Data[0] do
begin
FX := 10; FY := 10; FR := 30;
FRgn := CreateEllipticRgn(FX, FY, FX + FR, FY + FR);
end;
with Data[1] do
begin
FX := 120; FY := 130; FR := 30;
FRgn := CreateEllipticRgn(FX, FY, FX + FR, FY + FR);
end;
with Data[2] do
begin
FX := 100; FY := 40; FR := 30;
FRgn := CreateEllipticRgn(FX, FY, FX + FR, FY + FR);
end;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
Res: Bool;
I: Integer;
begin
for I := Low(Data) to High(Data) do
begin
Res := PtInRegion(Data[I].FRgn, X, Y);
if Res then
begin
ShowMessage('You clicked circle ' + IntToStr(I + 1));
Break;
end;
end;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
I: Integer;
begin
with Self.Canvas do
begin
Pen.Width := 2;
Pen.Color := clBlack;
Brush.Color := clRed;
end;
for I := Low(Data) to High(Data) do
Self.Canvas.Ellipse(Data[I].FX, Data[I].FY, Data[I].FX + Data[I].FR, Data[I].FY + Data[I].FR);
end;