非常紧急的问题---如何对动态产生的图片进行拖动和复制粘贴 ( 积分: 100 )

  • 主题发起人 主题发起人 purexiaoren
  • 开始时间 开始时间
P

purexiaoren

Unregistered / Unconfirmed
GUEST, unregistred user!
var
Form1: TForm1;
img:array[1..10] of timage; //定义动态产生十个图片
num:integer;
flag:integer;
cuspos:tpoint;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin //让图片动态产生在form1窗体中
inc(num);
img[num]:=Timage.Create(self);
img[num].Left:=100;
img[num].Top:=100;
img[num].AutoSize:=true;
if openpicturedialog1.Execute then begin
img[num].Parent:=form1;
img[num].Picture.LoadFromFile(openpicturedialog1.FileName);
end;
img[num].Cursor:=crHandPoint; //对图片的拖动
img[num].OnMouseDown:=img1MouseDown;
img[num].OnMousemove:=img1Mousemove;
img[num].OnMouseup:=img1Mouseup;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
num:=0;
flag:=0;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
inc(Num); //对图片的粘贴
img[num]:=Timage.Create(self);
img[num].Left:=img[num-1].Left+img[num-1].Width+10;
img[num].Top:=img[num-1].Top;
img[num].AutoSize:=true;
img[num].Parent:=form1;
img[num].Picture:=img[flag].Picture;
end;

procedure TForm1.abc1MouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
begin
flag:=1;
end;


procedure TForm1.img1MouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
begin
if (button=mbleft) then begin
cuspos:=point(x,y);
img[num].Tag:=1;
end;
end;

procedure tform1.img1mousemove(sender:tobject; shift: tshiftstate; x,y: integer);
begin
if img[num].Tag=1 then begin
img[num].Left:=img[num].Left-(cuspos.X-x);
img[num].Top:=img[num].Top-(cuspos.Y-y);
end;
end;

procedure TForm1.abc2MouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
begin
flag:=2;
end;

procedure TForm1.Img1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
img[num].Tag:=0;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin //对图片的复制
inc(Num);
if num>1 then begin
img[num].Left:=img[num-1].Left+img[num-1].Width+10;
img[num].Top:=img[num-1].Top;
end;
img[num].Parent:=form1;
case num of
1:img[num].OnMouseDown:=abc1mousedown;
2:img[num].OnMouseDown:=abc2MouseDown;
end;
end;
end.
请高手帮我看下问题出在哪啊
我感谢万分
[:(] [:(] [:(] [:(]
 
var
Form1: TForm1;
img:array[1..10] of timage; //定义动态产生十个图片
num:integer;
flag:integer;
cuspos:tpoint;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin //让图片动态产生在form1窗体中
inc(num);
img[num]:=Timage.Create(self);
img[num].Left:=100;
img[num].Top:=100;
img[num].AutoSize:=true;
if openpicturedialog1.Execute then begin
img[num].Parent:=form1;
img[num].Picture.LoadFromFile(openpicturedialog1.FileName);
end;
img[num].Cursor:=crHandPoint; //对图片的拖动
img[num].OnMouseDown:=img1MouseDown;
img[num].OnMousemove:=img1Mousemove;
img[num].OnMouseup:=img1Mouseup;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
num:=0;
flag:=0;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
inc(Num); //对图片的粘贴
img[num]:=Timage.Create(self);
img[num].Left:=img[num-1].Left+img[num-1].Width+10;
img[num].Top:=img[num-1].Top;
img[num].AutoSize:=true;
img[num].Parent:=form1;
img[num].Picture:=img[flag].Picture;
end;

procedure TForm1.abc1MouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
begin
flag:=1;
end;


procedure TForm1.img1MouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
begin
if (button=mbleft) then begin
cuspos:=point(x,y);
img[num].Tag:=1;
end;
end;

procedure tform1.img1mousemove(sender:tobject; shift: tshiftstate; x,y: integer);
begin
if img[num].Tag=1 then begin
img[num].Left:=img[num].Left-(cuspos.X-x);
img[num].Top:=img[num].Top-(cuspos.Y-y);
end;
end;

procedure TForm1.abc2MouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
begin
flag:=2;
end;

procedure TForm1.Img1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
img[num].Tag:=0;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin //对图片的复制
inc(Num);
if num>1 then begin
img[num].Left:=img[num-1].Left+img[num-1].Width+10;
img[num].Top:=img[num-1].Top;
end;
img[num].Parent:=form1;
case num of
1:img[num].OnMouseDown:=abc1mousedown;
2:img[num].OnMouseDown:=abc2MouseDown;
end;
end;
end.
请高手帮我看下问题出在哪啊
我感谢万分
[:(] [:(] [:(] [:(]
 
同志们救救我吧
哪个高手回答下 啊
在下万分感谢哦
 
后退
顶部