// Pt est le tableau ou tu enregistre les positions de tes lignes. // X et Y sont les coordonnées de ta souris. var ARect : TRect; i : integer; begin for i := High(Pt) downto 0 do begin ARect := Rect(Pt[i,0].x,Pt[i,0].Y,Pt[i,1].x,Pt[i,1].Y); if PtInRect(ARect,Point(X,Y)) then begin ShowMessage('Vous avez cliqué sur la ligne ' + IntToStr(i + 1)); break; end; end; end;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question{ les déclarations : Uses Math; type TLigne = Record X1,Y1,X2,Y2 : Integer; end; TTabLignes = Array[0..NombreLigne-1] of TLigne; var TabLigne : TTabLignes; } procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var i, n : Integer; d, Resu : integer; begin Resu:=99999; n:=-1; for i:=0 to NombreLigne-1 do begin With TabLigne[i] do begin if PtInRect(Rect(Min(X1,X2)-1,Min(Y1,Y2)-1,Max(X1,X2)+1,Max(Y1,Y2)+1),Point(X,Y)) then begin d := abs (X*Y2-X2*Y + X1*Y-X*Y1 + X2*Y1-X1*Y2); if (d<Resu) then begin n:=i; Resu := d; end; end; end; end; Trouve := n; Invalidate; end;
d := abs (X*Y2-X2*Y + X1*Y-X*Y1 + X2*Y1-X1*Y2);