- Na seção Private declare a procedure abaixo:

private

procedure WMMove(var Msg: TWMMove); message WM_MOVE;

- Abaixo da palavra implementation escreva a procedure abaixo:

procedure TForm1.WMMove(var Msg: TWMMove);

begin

if Left < 0 then

Left := 0;

if Top < 0 then

Top := 0;

if Screen.Width - (Left + Width) < 0 then

Left := Screen.Width - Width;

if Screen.Height - (Top + Height) < 0 then

Top := Screen.Height - Height;

end;

Para testar:

- Execute o programa e tente arrastar o form para fora das margens da tela e veja o que acontece.