This is not necessarily how to Hide this button, nor is it how to ignore the click event of it either. Instead, this is how to actually disable the close button of a form by graying it out. Windows provides this ability, but it is not implemented in Delphi's VCL forms. Therefore, you need to do it yourself.
I added this to my form by adding a new boolean property "CloseButtonEnabled". By default of course this will be true, then set it to false as needed to disable (or gray out) the close button, and back to true to be normal again.
In the form's class...
type TForm1 = class(TForm) private fCloseButtonEnabled: Bool; procedure SetCloseButtonEnabled(const Value: Bool); public property CloseButtonEnabled: Bool read fCloseButtonEnabled write SetCloseButtonEnabled; end;
And in the implementation...
procedure TForm1.SetCloseButtonEnabled(const Value: Bool); var hSysMenu: HMENU; begin fCloseButtonEnabled := Value; hSysMenu:= GetSystemMenu(Self.Handle, False); if hSysMenu <> 0 then begin if Value then EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND or MF_ENABLED) else EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND or MF_GRAYED); DrawMenuBar(Self.Handle); end; end;