当前位置: 代码迷 >> Delphi >> panel上动态增加多个image控件。并且可以随意拖动图片位置?该如何处理
  详细解决方案

panel上动态增加多个image控件。并且可以随意拖动图片位置?该如何处理

热度:99   发布时间:2016-05-10 04:44:45.0
panel上动态增加多个image控件。并且可以随意拖动图片位置??
panel上动态增加多个image控件。并且可以随意拖动图片位置??

------解决方案--------------------
坛子里有过这个问题,搜一下吧
基本思想就是,自己写鼠标事件(move,down之类的),创建image时,将自己的事件赋予image的鼠标事件
------解决方案--------------------
自已再修改:
Delphi(Pascal) code
type  TForm1 = class(TForm)    Panel1: TPanel;    Button1: TButton;    procedure Button1Click(Sender: TObject);  private    { Private declarations }    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);  public    { Public declarations }  end;var  Form1: TForm1;implementationvar  OldX, OldY: Integer;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);var  img1, img2: TImage;begin  Panel1.DoubleBuffered := True;  img1 := TImage.Create(Self);  img1.Parent := Panel1;  img1.OnMouseDown := OnMouseDown;  img1.OnMouseMove := ImageMouseMove;  img1.Picture.LoadFromFile('d:\1.jpg');  img2 := TImage.Create(Self);  img2.Parent := Panel1;  img2.OnMouseDown := OnMouseDown;  img2.OnMouseMove := ImageMouseMove;  img2.Picture.LoadFromFile('d:\2.jpg');  img2.Left := 400;end;procedure TForm1.ImageMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  OldX := TImage(Sender).Left;  OldY := TImage(Sender).Top;end;procedure TForm1.ImageMouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);begin  Caption := Format('X: %d, Y: %d', [X, Y]);  if ssLeft in Shift then  begin    with TImage(Sender) do    begin      Left := Left + ClientToScreen(Point(X, Y)).X - ClientToScreen(Point(OldX, OldY)).X;      Top := Top + ClientToScreen(Point(X, Y)).Y - ClientToScreen(Point(OldX, OldY)).Y;    end;  end;end;
------解决方案--------------------
用 ImageEN 控件不好吗?
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Tue Jan 17 10:50:55 CST 2017
  • 最近登录:Tue Jan 17 10:50:55 CST 2017
  • 最近登录:Tue Jan 17 10:50:55 CST 2017
  • 最近登录:Tue Jan 17 10:50:55 CST 2017
  • 最近登录:Tue Jan 17 10:50:55 CST 2017