我把form的标题兰去掉了,我在form中另外一个地方想要实现form的拖动。要怎么做?

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    Const
      SC_DragMove = $F012 ; 
    begin
      ReleaseCapture;
      PERFORM(WM_SysCommand,SC_DragMove ,0)
    end;end.
      

  2.   

    procedure HitTest(var Msg: TWmNcHitTest);message wm_NcHitTest;对Msg.xPos,Msg.yPos进行判断,符合条件的
    Msg.Result:=htCaption;
      

  3.   

    也可以:) unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
      private
        { Private declarations }
        procedure HitTest(var Msg: TWmNcHitTest);message wm_NcHitTest;  public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.HitTest(var Msg: TWmNcHitTest) ;
    begin
      if (Msg.XPos > 20) and (Msg.YPos > 20) then
        Msg.Result := HtCaption ;
    end ;end.
      

  4.   

    是的,像 wjlsmail(计算机质子) 那样也可以,只是他有很多问题, 比如说直接放在窗体上的label,picture的单击等事件,都不能用了.你还可以通过一个控件的拖动事件来控制例如,你要通过一个picture拖动privateOriginalPos:TPoint;            //记录原始位置
        CurrentPos:TPoint;             //记录当前位置
        DownPos:TPoint;   procedure TForm1.titleimgMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      OriginalPos.x := Form1.Left;
      OriginalPos.y := Form1.Top;
      DownPos.x := X;
      DownPos.y := Y;
      DownPos := ClientToScreen(DownPos);
      if Button = mbLeft then
        MouseLButtonDown := true;
    end;procedure TForm1.titleimgMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      if MouseLButtonDown = true then
      begin
        CurrentPos.x := X;
        CurrentPos.y := Y;
        CurrentPos := ClientToScreen(CurrentPos);
        Form1.Left := OriginalPos.x + (CurrentPos.x - DownPos.x);
        Form1.Top := OriginalPos.y + (CurrentPos.y - DownPos.y);
      end;
    end;procedure TForm1.titleimgMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      MouseLButtonDown:=false;
    end;
      

  5.   

    保证你在任何地方或控件上都可以拖动窗口implementation{$R *.dfm}
    var
      dx,dy:integer;
      started:boolean=false;procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    begin
      if msg.message=wm_lbuttondown then
      begin
        dx:=mouse.CursorPos.x-form1.Left;
        dy:=mouse.CursorPos.Y-form1.Top;
        started:=true;
      end;
      if (msg.message=wm_mousemove) and (started) then
      begin
        form1.Left:=mouse.CursorPos.X-dx;
        form1.Top:=mouse.CursorPos.Y-dy;
      end;  if msg.message=wm_lbuttonup then
      begin
        started:=false;
      end;
    end;end.