How do I restrict a minimum form's width in FireMonkey? It used to be so easy in VCL - it just had Max and Min constraints in forms properties.
Just found out TForm
has a Constraints
property in Delphi 11.
Works perfectly for me without flickering.
Below is an updated version to Sunec's answer, to get rid of flickering.
According to MSDN Mouse_Event has been superseded and SendInput should be used instead: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event
uses WinApi.Windows;
procedure TForm1.FormResize(Sender: TObject);
var
LInput: TInput;
begin
if ClientHeight < MIN_HEIGHT then
begin
ClientHeight := MIN_HEIGHT;
FillMemory(@LInput, SizeOf(LInput), 0);
LInput.Itype := INPUT_MOUSE;
LInput.mi.dwFlags := MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP;
SendInput(1, LInput, SizeOf(LInput));
end;
if ClientWidth < MIN_WIDTH then
begin
ClientWidth := MIN_WIDTH;
FillMemory(@LInput, SizeOf(LInput), 0);
LInput.Itype := INPUT_MOUSE;
LInput.mi.dwFlags := MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP;
SendInput(1, LInput, SizeOf(LInput));
end;
end;
LaKraven, simulate a mouseUp event to get rid of that flickering.
if (Width > maxWidth) then
begin
Width := maxWidth;
Mouse_Event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
end;
Place this on the form's "OnResize" event, replace the values as appropriate. Granted, not the best solution in the world, but it'll get you by until the properties are reintroduced!
procedure TForm1.FormResize(Sender: TObject);
begin
if Width < 400 then
Width := 400;
if Height < 400 then
Height := 400;
end;
The above code is easy enough to change for any combination of maximums or minimums, so have fun!
Additionally for LaKraven's answer about FormResize based solution, use ClientWidth and ClientHeight instead of Width and Height to prevent stretching of the form.
procedure TForm1.FormResize(Sender: TObject);
begin
if ClientWidth < 400 then
ClientWidth := 400;
if ClientHeight < 400 then
ClientHeight := 400;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With