给你写,给分
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm1 = class(TForm)
Image1: TImage;
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormCreate(Sender: TObject);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
isdown:boolean;
ABitmap:TBitMap;
dx,dy,ux,uy,cs:integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
ABitmap:=TBitMap.Create;
ABitmap.Assign(Image1.Picture.Bitmap);
cs:=0;
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
dx:= X;
dy:= Y;
isdown:=true;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if isdown then
begin
if cs=0 then
begin
Image1.Canvas.FillRect(Image1.ClientRect);
Image1.Canvas.Draw(x-dx,y-dy,Abitmap);
end
else
begin
Image1.Canvas.FillRect(Image1.ClientRect);
Image1.Canvas.Draw(x+ux-dx,y+uy-dy,Abitmap);
end;
end;
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if cs=0 then
begin
ux:=x-dx;
uy:=y-dy;
Image1.Canvas.FillRect(Image1.ClientRect);
Image1.Canvas.Draw(ux,uy,Abitmap);
isdown:=false;
end
else
begin
ux:=x+ux-dx;
uy:=y+uy-dy;
Image1.Canvas.FillRect(Image1.ClientRect);
Image1.Canvas.Draw(ux,uy,Abitmap);
isdown:=false;
end;
inc(cs);
end;
end.