Comment limiter le déplacement d'un composant ?
Bonsoir à tous,
Je cherhce à limiter le déplacemt par drag and drop d'un composant situé dans un Timage lui même dans un scrollbox.
Voici le code :
Code:
1 2 3
| private
deplace: boolean;
xa, ya, xo, yo: integer; |
Code:
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
| implementation
{$R *.dfm}
procedure TForm1.TexteMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
begin
deplace := true;
xa := x;
ya := y;
end;
end;
procedure TForm1.TexteMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if deplace then begin
{ la souris comme hors de l'image. }
if not PtInRect(Rect(0, 0, image1.Width , image1.Height), Point(X, Y)) then
Exit
else
Texte.Left := Texte.Left + x - xa;
Texte.Top := Texte.Top + y - ya;
image1.Repaint;
end;
end;
procedure TForm1.TexteMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
deplace := false;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
deplace := false;
Image1.Picture.LoadFromFile('c:\test.bmp');
end;
end. |
Le code censé limité le déplacement du composant dans l'image est :
Code:
1 2
| if not PtInRect(Rect(0, 0, image1.Width , image1.Height), Point(X, Y)) then
Exit |
Walou , peanuts, ça marche pas ....:bug:
Merci de votre aide.