How to prevent moving of application window
If you want to “lock” your application window position and prevent user from moving it, it’s really simple.
The application form will be completely immovable, but user can still resize, minimize or maximize it. How does it work? We will just remove “move” command from system menu using simple code in OnCreate event of the form. In second part of code (OnClick event of button), we will enable moving again.
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 |
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin DeleteMenu(GetSystemMenu(Handle, False), SC_MOVE, MF_BYCOMMAND); end; procedure TForm1.Button1Click(Sender: TObject); begin GetSystemMenu(Handle, True); end; end. |