Reputation: 233
I want to have a form resize proportionally when the user resizes it. I have done this in the event OnCanResize
with the following code:
NewHeight := Round(Height / Width* NewWidth);
To prevent the user maximizing the form by clicking the maximize button I managed to disable it treating the message WMSysCommand
with the following code :
if (AMsg.CmdType = SC_MAXIMIZE) then MessageBeep(0);
What I have not managed to do is to prevent maximizing the form when the user double clicks on the title bar. Is there any way to do it in Delphi?
I hope it is clear that I don't want to prevent the user from resizing the form. I just want to prevent resizing when clicking the maximize button and double clicking the title bar.
Upvotes: 1
Views: 3371
Reputation: 21242
An alternative to @TLama's obvious answer:
SetWindowLong(Handle, GWL_STYLE,
GetWindowLong(Handle, GWL_STYLE) and not WS_MAXIMIZEBOX);
As opposed to setting BorderIcons
, this will not force a re-creation of the window handle (no call will be made to RecreateWnd
). This might be useful when switching/changing your window style dynamically without loosing the window state/handle.
Upvotes: 7
Reputation: 76693
As first, remove the workaround you have used in the WM_SYSCOMMAND
message handler and then just remove biMaximize
option from the BorderIcons
property of your form or in other words by setting the BorderIcons.biMaximize
to False in the Object Inspector, and you'll get maximize button as well as form title double click maximize disabled.
At run-time you could simply use:
BorderIcons := BorderIcons - [biMaximize]
Upvotes: 7