Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Imaging.pngimage;
- type
- TForm1 = class(TForm)
- Image1: TImage;
- procedure FormCreate(Sender: TObject);
- procedure ImageMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure ImageMouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- img1, img2: Timage;
- StartCoord: TPoint;
- Move: Boolean;
- implementation
- {$R *.dfm}
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- img1 := TImage.Create(self);
- img1.Parent := Form1;
- img1.Picture.LoadFromFile('G:\Downloads\bb.png');
- img1.OnMouseDown := ImageMouseDown;
- img1.OnMouseMove := ImageMouseMove;
- img1.OnMouseUp := ImageMouseUp;
- img1.Stretch := True;
- end;
- procedure TForm1.ImageMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- begin
- with Sender as TImage do
- begin
- if Move then
- begin
- if X > StartCoord.X then
- Image1.Left := Image1.Left + (X - StartCoord.X);
- if X < StartCoord.X then
- Image1.Left := Image1.Left - (StartCoord.X - X);
- if Y > StartCoord.Y then
- Image1.Top := Image1.Top + (Y - StartCoord.Y);
- if Y < StartCoord.Y then
- Image1.Top := Image1.Top - (StartCoord.Y - Y);
- end;
- end;
- end;
- procedure TForm1.ImageMouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- with sender as TImage do
- Move := False;
- end;
- procedure TForm1.ImageMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- begin
- with sender as TImage do
- begin
- Move := True;
- StartCoord.X := X;
- StartCoord.Y := Y;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement