



O código abaixo é um exemplo de como fazer para impedir de um formulário
seja arrastado para fora das margens da tela.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm1 = class(TForm) Button1: TButton; private procedure WMMove(var Msg: TWMMove); message WM_MOVE; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} { TForm1 } 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; end. |
Dúvidas ou sugestões deixe nos comentários do post.