如果不要关闭按钮什么的就将Form的BorderStyle设为BsNone
如果要就只有用消息了

解决方案 »

  1.   

    form.borderstyle:=bsnone;在窗体上加关闭按钮。
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type
      TForm1 = class(TForm)
      private
        procedure wmnchittest(var msg:twmnchittest); message wm_nchittest;
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.wmnchittest(var msg:twmnchittest);
    begin
    inherited;
    if (htcaption = msg.result) then msg.result:=htclient;
    end;
    end.
    即可 上面的关键代码虽然只有两行,但它实现了鼠标直接拖动窗体的目的。
    代码的原理是利用窗体的WM_NCHITTEST消息,这个消息是当光标移动、
    鼠标按下或释放时发生的,当程序检测到鼠标在窗体中按下的消息后
    (消息的值为htClient),将鼠标在标题栏上按下时产生的消息
    (值为htCaption)传递出去,这样就巧妙的欺骗程序认为是标题栏被按下
    ,当然就可拖动窗体了。
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure onMove(var msg:TMessage);message wm_move;
      end;var
      Form1: TForm1;
      x,y,w,h:integer;
      flag:boolean;
    implementation{$R *.dfm}{ TForm1 }procedure TForm1.onMove(var msg: TMessage);
    begin
      if flag=false then begin
        x:=left;
        y:=top;
        w:=width;
        h:=height;
        flag:=true;
      end;
      movewindow(handle,x,y,w,h,true);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      flag:=false;
    end;end.
    //记录form的原始位置,截获wm_move,使用movewindow()
      

  4.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure onMove(var msg:TMessage);message wm_move;
      end;var
      Form1: TForm1;
      x,y,w,h:integer;
      flag:boolean;
    implementation{$R *.dfm}{ TForm1 }procedure TForm1.onMove(var msg: TMessage);
    begin
      if flag=false then begin
        x:=left;
        y:=top;
        w:=width;
        h:=height;
        flag:=true;
      end;
      movewindow(handle,x,y,w,h,true);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      flag:=false;
    end;end.
    记录form原始位置,拦截wm_move,使用movewindow()
      

  5.   

    得到这个消息:
    procedure wmnchittest(var msg:twmnchittest); message wm_nchittest;
      

  6.   

    我用了一个界面控件,所以form上已经没有标题栏,但可以移动。
    用(if  (htcaption  =  msg.result)  then  msg.result:=htclient;)也不行,可能这个控件就是用这种方法使form没有标题栏也可以移动,用wm_move把问题解决了,谢谢各位的参与!
    给分喽!