怎样做到类似ACDSee的移动功能,当图片较大时鼠标变成"手",并可以移动图片;另外当按住ctrl键时,鼠标变成"放大"形状,点击鼠标能放大图形.

解决方案 »

  1.   

    用手型指针制作资源文件,将其编译进程序中!{$R xxx.res}OnMouseDown事件中改变Screen.Cursor,并改变一个标记变量!OnMouseUp事件还原Screen.Cursor
    Screen.Cursor:=crDefault;OnMouseMove事件中编写代码根据X,Y的值,长,宽等数据移动Image控件!
      

  2.   

    我的一段代码,请参考。hand_pt是个全局变量。procedure Tmain.img1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      allow_move:=0;
      if (button=mbleft) and (img1.Tag>0) then
        begin
          allow_move:=1;
          starttop:=img1.top;
          startleft:=img1.left;      GetCursorPos(hand_pt);  //获取光标位置
          img1.Cursor:=crhandpoint;
        end;
    end;
    procedure Tmain.img1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    var
     d_x,d_y:integer;
     now_pt:Tpoint;
    begin
      if allow_move=0 then
        exit;
      GetCursorPos(now_pt);  //获取光标位置
      d_x:=now_pt.x-hand_pt.x;
      d_y:=now_pt.y-hand_pt.y;
        if img1.Tag>0 then
          begin
            if d_y<>0 then
              begin
                img1.top:=startTop+d_y;
              end;
            if d_x<>0 then
              begin
                img1.left:=startleft+d_x;
              end;
          end;
    end;
    procedure Tmain.img1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if allow_move=1 then
        allow_move:=0;
    end;
      

  3.   

    我的移动图像方法,给你参考
    procedure TTMainWnd.Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if button=mbleft then
         begin
           ReleaseCapture;
           sendmessage(Handle,WM_SYSCOMMAND,SC_MOVE or htclient,0);
           self.Hide;
           self.Show;
         end;
    end;