写的很粗糙……凑合看下吧
var
Form1: TForm1;
MouseStatus : Integer;
OldImgPoint : TPoint;
OldLabelPoint : TPoint;
implementation
{$R *.dfm}
procedure TForm1.Image1MouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
MouseStatus := 1;
OldImgPoint.X := X;
OldImgPoint.Y := Y;
OldLabelPoint.X := Label1.Left - Image1.Left;
OldLabelPoint.X := Label1.Top - Image1.Top;
end;
procedure TForm1.Image1MouseUp(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
MouseStatus := 0;
end;
procedure TForm1.Image1MouseMove(Sender: TObject;
Shift: TShiftState;
X,
Y: Integer);
begin
if MouseStatus=1 then
begin
with Image1do
begin
Left := Left - OldImgPoint.X + X;
Top := Top - OldImgPoint.Y + Y;
end;
with Label1do
begin
Left := Image1.Left + OldLabelPoint.X;
Top := Image1.Top + OldLabelPoint.Y;
end;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MouseStatus := 0;
end;