如何让Delphi的窗体无论怎么拖动,都无法拖出电脑屏幕的范围,
比如说:窗体的最顶端不会超过屏幕上限,最左边也无法超过屏幕的最左端。这样的效果。
请赐教,谢谢。

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);  private
        { Private declarations }
      public
        procedure MyMsg(Var Msg : TMsg) ; Message WM_MOVE;
      end;var
      Form1: TForm1;implementation{$R *.dfm}{ TT }
    procedure TForm1.FormCreate(Sender: TObject);
    beginend;procedure TForm1.MyMsg(var Msg: TMsg);
    begin
      if Self.Left < 0 then Self.Left := 0;
      if self.Top < 0  then self.Top := 0;
      if Self.Top + Self.Height > Screen.Height then Self.Top := Screen.Height - Self.Height;
      if Self.left + Self.Width > Screen.Width then Self.left := Screen.Width - Self.Width;end;end.
      

  2.   

    处理WM_Move消息,自己进行计算
      

  3.   

    楼上都是正解,处理WM_Move消息
      

  4.   

    拖动的时候有重绘的过程设置窗体的doublebufferd属性为true试试
      

  5.   

    doublebuffer只是对窗体里面的控件移动有用吧?