Mega Code Archive

 
Categories / Delphi / Forms
 

How can I prevent the user from moving or sizing my form

Title: How can I prevent the user from moving or sizing my form? Question: How can I prevent the user from moving or sizing my form? Answer: Trap the Windows WM_WINDOWPOSCHANGING message and "or" the flags of the WindowPos structure passed in the message's lparam parameter with the predefined constants SWP_NOMOVE and SWP_NOSIZE. type TForm1 = class(TForm) private procedure WMPosChange(var Message: TWMWINDOWPOSCHANGING); message WM_WINDOWPOSCHANGING; public end; var Form1: TForm1; implementation {$R *.DFM} procedure Tform1.WMPosChange(var Message: TWMWINDOWPOSCHANGING); begin PWindowPos(TMessage(Message).lParam).Flags := PWindowPos(TMessage(Message).lParam).Flags or SWP_NOMOVE or SWP_NOSIZE; end;