给你个完全的,可以加分了吧
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls, ToolWin;
type
TForm1 = class(TForm)
Label1: TLabel;
Image1: TImage;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
procedure FormCreate(Sender: TObject);
procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Label1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ToolButton1Click(Sender: TObject);
procedure FormClick(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
bdrag:boolean;
x1,y1:integer;
newobj_x,newobj_y:integer;
newobj_tag:integer;
myimage: TImage;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
bdrag:=false;
newobj_tag:=1;
end;
procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
x1:=x;
y1:=y;
bdrag:=true;
end;
procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if bdrag then
begin
label1.left:=label1.left+x-x1;
label1.top:=label1.top+y-y1;
end;{if}
end;
procedure TForm1.Label1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
bdrag:=false;
end;
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
x1:=x;
y1:=y;
bdrag:=true;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if bdrag then
begin
image1.left:=image1.left+x-x1;
image1.top:=image1.top+y-y1;
end;{if}
end;
procedure TForm1.Image1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
bdrag:=false;
end;
procedure TForm1.ToolButton1Click(Sender: TObject);
begin
newobj_tag:=newobj_tag+1;
MyImage:=TImage.Create(self);
myimage.Picture.LoadFromFile ('d:/test/picmove/ufo.bmp');
myimage.Stretch :=true;
end;
procedure TForm1.FormClick(Sender: TObject);
begin
myimage.Left :=newobj_x;
myimage.Top :=newobj_y;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
newobj_x:=x;
newobj_y:=y;
myimage.parent:=form1;
end;
end.