Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.10 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Imaging.pngimage;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Image1: TImage;
  12.     procedure FormCreate(Sender: TObject);
  13.     procedure ImageMouseDown(Sender: TObject; Button: TMouseButton;
  14.       Shift: TShiftState; X, Y: Integer);
  15.     procedure ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
  16.       Y: Integer);
  17.     procedure ImageMouseUp(Sender: TObject; Button: TMouseButton;
  18.       Shift: TShiftState; X, Y: Integer);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.   img1, img2: Timage;
  28.   StartCoord: TPoint;
  29.   Move: Boolean;
  30.  
  31. implementation
  32.  
  33. {$R *.dfm}
  34.  
  35. procedure TForm1.FormCreate(Sender: TObject);
  36. begin
  37.    img1 := TImage.Create(self);
  38.    img1.Parent := Form1;
  39.    img1.Picture.LoadFromFile('G:\Downloads\bb.png');
  40.    img1.OnMouseDown := ImageMouseDown;
  41.    img1.OnMouseMove := ImageMouseMove;
  42.    img1.OnMouseUp := ImageMouseUp;
  43.    img1.Stretch := True;
  44. end;
  45.  
  46. procedure TForm1.ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
  47.   Y: Integer);
  48. begin
  49.    with Sender as TImage do
  50.    begin
  51.       if Move then
  52.       begin
  53.          if X > StartCoord.X then
  54.             Image1.Left := Image1.Left + (X - StartCoord.X);
  55.          if X < StartCoord.X then
  56.             Image1.Left := Image1.Left - (StartCoord.X - X);
  57.          if Y > StartCoord.Y then
  58.             Image1.Top := Image1.Top + (Y - StartCoord.Y);
  59.          if Y < StartCoord.Y then
  60.             Image1.Top := Image1.Top  - (StartCoord.Y - Y);
  61.       end;
  62.    end;
  63. end;
  64.  
  65. procedure TForm1.ImageMouseUp(Sender: TObject; Button: TMouseButton;
  66.   Shift: TShiftState; X, Y: Integer);
  67. begin
  68.     with sender as TImage do
  69.       Move := False;
  70. end;
  71.  
  72. procedure TForm1.ImageMouseDown(Sender: TObject; Button: TMouseButton;
  73.   Shift: TShiftState; X, Y: Integer);
  74. begin
  75.     with sender as TImage do
  76.     begin
  77.    Move := True;
  78.    StartCoord.X := X;
  79.    StartCoord.Y := Y;
  80.     end;
  81. end;
  82.  
  83. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement