unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
procedure Move(var Message:Tmessage); message WM_MOVING;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Move(var Message: Tmessage);
var R:TRect;
begin
R:=Rect(10,10,1000,700); //换成你的mainform的ClientRect
if PRect(Message.lParam)^.Left<R.Left then
begin
PRect(Message.lParam)^.Left:=R.Left;
PRect(Message.lParam)^.Right:=R.Left+Width;
end;
if PRect(Message.lParam)^.Top<R.Top then
begin
PRect(Message.lParam)^.Top:=R.Top;
PRect(Message.lParam)^.Bottom:=R.Top+Height;
end;
if PRect(Message.lParam)^.Right>R.Right then
begin
PRect(Message.lParam)^.Left:=R.Right-Width;
PRect(Message.lParam)^.Right:=R.Right;
end;
if PRect(Message.lParam)^.Bottom>R.Bottom then
begin
PRect(Message.lParam)^.Top:=R.Bottom-Height;
PRect(Message.lParam)^.Bottom:=R.Bottom;
end;
inherited;
end;
end.