如何限制使窗体不被移动出屏幕以外,还可以全屏幕

解决方案 »

  1.   

    This is due to the default handling (by Windows) of the WM_GETMINMAXINFO  message, it sets the max size to the screen size. Add a handler for this message, first call inherited in it and then change the max size.  Emulating full screen mode:   private  // in form declaration    Procedure WMGetMinMaxInfo(Var msg: TWMGetMinMaxInfo);      message WM_GETMINMAXINFO;  Procedure TForm1.WMGetMinMaxInfo(Var msg: TWMGetMinMaxInfo);  Begin    inherited;    With msg.MinMaxInfo^.ptMaxTrackSize Do Begin      X := GetDeviceCaps( Canvas.handle, HORZRES ) + (Width - ClientWidth);      Y := GetDeviceCaps( Canvas.handle, VERTRES ) + (Height - ClientHeight);    End;  End; procedure TForm1.Button2Click(Sender: TObject);Const  Rect: TRect = (Left:0; Top:0; Right:0; Bottom:0);begin  If Left > 0 Then Begin    Rect := BoundsRect;    SetBounds(      Left - ClientOrigin.X,      Top - ClientOrigin.Y,      GetDeviceCaps( Canvas.handle, HORZRES ) + (Width - ClientWidth),      GetDeviceCaps( Canvas.handle, VERTRES ) + (Height - ClientHeight ));    Label2.caption := IntToStr(GetDeviceCaps( Canvas.handle, VERTRES ));  End  Else    BoundsRect := Rect;end; 这例子是大过屏幕,分析一下变成限制小于屏幕如何吧
      

  2.   

    WM_GETMINMAXINFO 这个消息不错的了
    简单一点的可以在 ONMOUSEMOVE事件中 判断窗体的位置+大小是否超出范围
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      r: TRect;
    begin
      r.TopLeft := Panel1.ClientToScreen(Panel1.ClientRect.TopLeft);
      r.BottomRight := 
        Panel1.ClientToScreen(Panel1.ClientRect.BottomRight);
      ClipCursor(@R);
    end;
    这个是把限制鼠标只能在panel内移动,不能移到其它地方
    把这个修改成为屏幕如何做到阿
      

  4.   

    procedure TForm_main.AutoAdaptForm(Sender: TObject) ;
    var
      lpRect:TRect;
    begin
      SystemParametersInfo(SPI_GETWORKAREA,0,@lpRect,0);
      Form_main.Left := lpRect.left;
      Form_main.Top  := lpRect.Top;
      Form_main.width := lpRect.right - lpRect.left;
      Form_main.Height := lpRect.bottom - lpRect.Top;
      Form_main.Update ;
    end;让窗体自动适应桌面大小 为何多了上下一截到屏幕外了直接设置align:=alClient;如上则其它的控件位置控制又变了,
    用form1.borderstyle:=bsnone;
    setbounds(0,0,screen.width,screen.height);
    则上面的蓝边没了
    有无其它法
      Form_main代表桌面是吗,我找到的这个例子,如何修改到我的例子里?