使用以下代码在某个控件的 onMouseDown 事件里,能实现运行状态拖动的效果
     ReleaseCapture;
     Sendmessage((Sender as TWinControl).Handle,WM_syscommand,$F012,0); 
     但我现在有个问题,当拖动停止的时候,怎么捕获鼠标放开了时候! 我需要在控件停止拖动的
时候处理一些东西,比例获得控件新的位置等之类的信息,请高手指定,应该怎么处理,要写什么样的
代码? 

解决方案 »

  1.   

    MouseUp事件中写代码啊,当然最好设一下标志,这样比较好判断些procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      FMoving :=True;
      //....
    end;procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      Fmoving := False;
      //.....
    end;
      

  2.   

    faq里有:原帖找不到了//==============================================================================//任意摆布一个控件(拖动、放大、缩小)******************************************//==============================================================================procedure  ManipulateControl(WinControl:  TWinControl;  Shift:  TShiftState;  X,  Y,  Precision:  integer);//Precision:精度,该方法可以在onmousemove中调用var  SC_MANIPULATE:  Word;begin
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
       //光标在控件的最左侧**********************************************************
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
                 if  (X<=Precision)  and  (Y>Precision)  and  (Y<WinControl.Height-Precision)
     
       then  begin                 SC_MANIPULATE    :=  $F001;  
     
                     WinControl.Cursor  :=  crSizeWE;  
     
                 end     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     
       //光标在控件的最右侧**********************************************************  
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
       else  if  (X>=WinControl.Width-Precision)  and  (Y>Precision)  and  (Y<WinControl.Height-Precision)  
     
       then  begin                   SC_MANIPULATE    :=  $F002;  
     
                     WinControl.Cursor  :=  crSizeWE;  
     
                 end
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     
       //光标在控件的最上侧**********************************************************     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     
       else  if  (X>Precision)  and  (X<WinControl.Width-Precision)  and  (Y<=Precision)  
     
       then  begin
     
                     SC_MANIPULATE    :=  $F003;  
     
                     WinControl.Cursor  :=  crSizeNS;               end  
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     
       //光标在控件的左上角**********************************************************
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     
       else  if  (X<=Precision)  and  (Y<=Precision)     then  begin  
     
                     SC_MANIPULATE    :=  $F004;  
     
                     WinControl.Cursor  :=  crSizeNWSE;
     
                 end  
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     //光标在控件的右上角**********************************************************  
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     
       else  if  (X>=WinControl.Width-Precision)  and  (Y<=Precision)
     
       then  begin  
     
                     SC_MANIPULATE    :=  $F005;                   WinControl.Cursor  :=  crSizeNESW  ;  
     
                 end  
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
       //光标在控件的最下侧**********************************************************  
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     else  if  (X>Precision)  and  (X<WinControl.Width-Precision)  and  (Y>=WinControl.Height-Precision)  
     
       then  begin  
     
                     SC_MANIPULATE    :=  $F006;
     
                     WinControl.Cursor  :=  crSizeNS;  
     
                 end     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     
       //光标在控件的左下角**********************************************************  
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     
       else  if  (X<=Precision)  and  (Y>=WinControl.Height-Precision)  
     
       then  begin                   SC_MANIPULATE    :=  $F007;  
     
                     WinControl.Cursor  :=  crSizeNESW;  
     
                 end
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     
       //光标在控件的右下角**********************************************************     //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     
       else  if  (X>=WinControl.Width-Precision)  and  (Y>=WinControl.Height-Precision)  
     
       then  begin
     
                     SC_MANIPULATE    :=  $F008;  
     
                     WinControl.Cursor  :=  crSizeNWSE;               end  
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     
       //光标在控件的客户区(移动整个控件)******************************************
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     
       else  if  (X>5)  and  (Y>5)  and  (X<WinControl.Width-5)  and  (Y<WinControl.Height-5)     then  begin  
     
                     SC_MANIPULATE    :=  $F009;  
     
                     WinControl.Cursor  :=  crSizeAll;
     
                 end  
     
       else  begin                   SC_MANIPULATE  :=  $F000;
     
                     WinControl.Cursor  :=  crDefault;  
     
                 end;
     
       //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
     
       if  Shift=[ssLeft]  then     begin  
     
           ReleaseCapture;  
     
           WinControl.Perform(WM_SYSCOMMAND,  SC_MANIPULATE,  0);
     
       end;      end;procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin  
       ManipulateControl((Sender  as  TWinControl),  Shift,  X,  Y,  10);  
     
    end;
      

  3.   

    两种方法
    1。
    procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      ReleaseCapture;
      panel1.perform(WM_SysCommand, $F012, 0);end;2。var
      Form1: TForm1;
      MoveEn:Boolean;
      XY:TPoint;
    implementation{$R *.DFM}procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if Button =mbLeft then
        begin
          MoveEn:=True;
          XY.x :=x;
          XY.y :=y;
        end;
    end;procedure TForm1.Label1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
          MoveEn:=False;end;procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      if MoveEn then
        begin
          Label1.Left  :=Label1.Left +(x-XY.x);
          Label1.Top :=Label1.Top +(y-XY.y);
        end;end;
      

  4.   

    首先很感谢各位的关注
    但是感觉你们的回答不是我想要的答案啊
    OnMouseDown里面写了 
     ReleaseCapture;
     Sendmessage(panel1.Handle,wm_syscommand,$F009,0);
    后,onMouseUp 是不响应的啊! 里面写代码有什么用了!