小弟想要移动一个控件,不如是Tedit,但是当我移动后,发现控件多了边框
具体设置如下:dragkind为dkdock,dragmode为dmautomatic.
我要实现的效果是和delphi环境中拖放控件的效果是一样的。另:请问如何向窗体发送消息wm_paint

解决方案 »

  1.   


    type
      TForm1 = class(TForm)
        procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Integer);
        procedure Label1MouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        FMouseDown: Boolean;
        FOldPoint: TPoint;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Label1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      FMouseDown := mbLeft = Button;
      FOldPoint := Point(X, Y);
    end;procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      if not FMouseDown then Exit;
      TControl(Sender).Left := TControl(Sender).Left + (X - FOldPoint.X);
      TControl(Sender).Top := TControl(Sender).Top + (Y - FOldPoint.Y);
    end;procedure TForm1.Label1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      FMouseDown := False;
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      I: Integer;
    begin
      for I := 1 to 10 do
        with TLabel.Create(Self) do begin
          Name := 'MyLabel' + IntToStr(I);
          Parent := Self;
          Top := I * Height;
          Cursor := crHandPoint;
          OnMouseDown := Label1MouseDown;
          OnMouseMove := Label1MouseMove;
          OnMouseUp := Label1MouseUp;
        end;
    end;
      

  2.   

    // 任意摆布一个控件 ( 拖动、放大、缩小 )******************************************//==============================================================================procedure ManipulateControl(Control: TControl; Shift: TShiftState; X, Y, Precision: integer);var SC_MANIPULATE: Word;begin  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  // 光标在控件的最左侧 **********************************************************  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       if (X<=Precision) and (Y>Precision) and (Y<Control.Height-Precision)  then begin         SC_MANIPULATE  := $F001;         Control.Cursor := crSizeWE;       end  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  // 光标在控件的最右侧 **********************************************************  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  else if (X>=Control.Width-Precision) and (Y>Precision) and (Y<Control.Height-Precision)  then begin         SC_MANIPULATE  := $F002;         Control.Cursor := crSizeWE;       end  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  // 光标在控件的最上侧 **********************************************************  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  else if (X>Precision) and (X<Control.Width-Precision) and (Y<=Precision)  then begin         SC_MANIPULATE  := $F003;         Control.Cursor := crSizeNS;       end  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  // 光标在控件的左上角 **********************************************************  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  else if (X<=Precision) and (Y<=Precision)  then begin         SC_MANIPULATE  := $F004;         Control.Cursor := crSizeNWSE;       end  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  // 光标在控件的右上角 **********************************************************  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  else if (X>=Control.Width-Precision) and (Y<=Precision)  then begin         SC_MANIPULATE  := $F005;         Control.Cursor := crSizeNESW    ;       end  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  // 光标在控件的最下侧 **********************************************************  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  else if (X>Precision) and (X<Control.Width-Precision) and (Y>=Control.Height-Precision)  then begin         SC_MANIPULATE  := $F006;         Control.Cursor := crSizeNS;       end  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  // 光标在控件的左下角 **********************************************************  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  else if (X<=Precision) and (Y>=Control.Height-Precision)  then begin         SC_MANIPULATE  := $F007;         Control.Cursor := crSizeNESW;       end  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  // 光标在控件的右下角 **********************************************************  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  else if (X>=Control.Width-Precision) and (Y>=Control.Height-Precision)  then begin         SC_MANIPULATE  := $F008;         Control.Cursor := crSizeNWSE;       end  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  // 光标在控件的客户区 ( 移动整个控件 )******************************************  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  else if (X>5) and (Y>5) and (X<Control.Width-5) and (Y<Control.Height-5)  then begin         SC_MANIPULATE  := $F009;         Control.Cursor := crSizeAll;       end  else begin         SC_MANIPULATE := $F000;         Control.Cursor := crDefault;       end;  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  if Shift=[ssLeft] then  begin    ReleaseCapture;    Control.Perform(WM_SYSCOMMAND, SC_MANIPULATE, 0);  end;end;
    example :
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~procedure TForm_Main.Button1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);begin  Caption := IntToStr(X) + '/' + IntToStr(Y);  ManipulateControl((Sender as TControl), Shift, X, Y, 10);end;10 为精度 
      

  3.   

    回l0f(凌风) :
    我现在要创建TQRtext,但是TQRtext没有鼠标事件,如果要移动它怎么怎么做?谢谢!!!