以下是我找到的静态组件(就是用鼠标拖上去的组件)的拖动、放大、缩小的代码,可是怎样实现动态创建的组件的拖动、放大、缩小?只有10分了全部奉上,希望大家不要介意,他日一定补偿,多谢!!!
//任意摆布一个控件(拖动、放大、缩小)******************************************  
 
//==============================================================================  
 
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  TForm_Main.Button1MouseMove(Sender:  TObject;  Shift:  TShiftState;  X,  Y:  Integer);  
 
begin  
 
   Caption  :=  IntToStr(X)  +  '/'  +  IntToStr(Y);  
 
   ManipulateControl((Sender  as  TWinControl),  Shift,  X,  Y,  10);  
 
end;  

解决方案 »

  1.   

    重载动态控件的MouseMove事件就可以了
      

  2.   

    回复:
    例如:Btn:=TButton.create(self);
          Btn.Button1MouseMove=Button1MouseMove(Sender:  TObject;  Shift:  TShiftState;  X,  Y:  Integer);Button1MouseMove是你在其他的地方写的过程。其他的操作也这样。
      

  3.   

    这个问题不是这么简单的操作! 考虑的因素很多。比如在移动的过程中是否想把对象移出其父对象的范围。而是在整个Form上移动。这就要求在移动的过程中考虑控件父类的变化!
      

  4.   


    可以参考一下例如FastReport等工具的报表设计窗体的源码