请问当我鼠标离开Form1的时候就让Form1自动关闭,这样的功能我要怎么做?
我查了CM_MOUSEENTER;   CM_MOUSELEAVE;这两个函数后我还是搞不明白要怎么写.要把他写在窗体的那个事件里面.请各位大哥赐教

解决方案 »

  1.   

    类似如下功能procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      if ( form1.top+form1.Height )> y then
        close;
    end;
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, DB, ADODB, Grids, DBGrids;type
      TForm1 = class(TForm)
        DBGrid1: TDBGrid;
        DataSource1: TDataSource;
        ADOConnection1: TADOConnection;
        ADOQuery1: TADOTable;
      private
        { Private declarations }
        procedure DoMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;//这个是鼠标离开的消息,要定义消息处理过程(函数)
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.DoMouseLeave(var Msg: TMessage);
    begin
      inherited;
      Close;
    end;end.
      

  3.   

    如果窗体中有其它控件,则上一楼会出现问题,所以再加上个判断就好,即得到当前cursor的坐标,然后看它的坐标值是否在本窗体内,如果在就不执行关闭操作,得到当前鼠标:GetCursorPos(P),P为TPoint类型
      

  4.   

    用了blazingfire的方法是的,我的窗体上有其它控件,只要鼠标一移动到那些控件的上面的话也会自动关闭掉.这个不知道要怎么处理
      

  5.   

    wm_mouse消息中处理
    自己判断鼠标所在的位置.
      

  6.   

    放个定时器,然后定时器里面写
    procedure TForm1.Timer1Timer(Sender: TObject);
    var
       pos:Tpoint;
       gethandle:THandle;
    begin
    GetCursorPos(pos);            
    gethandle:=GetAncestor(WindowFromPoint(pos),  GA_ROOT);
    if  per_handle<>self.Handle then
       close;
    end;