TGroupBox.AutoSize is broken? lazarus / 31-LCL ---------------------------------------------------------------------- LemonParty · 2025-08-10 11:09 Hello. I have a TGroupBox and I create few checkboxes in runtime inside this groupbox. The problem is that groupbox not expanding so only few first checkboxes are visible. Is this some kind of bug or it should be like this? ---------------------------------------------------------------------- wp · 2025-08-10 12:20 Cannot confirm. The attached demo works correctly (Laz/main + fpc 3.2.2, Windows 11). Please post a similar demo to show the issue. ---------------------------------------------------------------------- jamie · 2025-08-10 12:54 This works for me on my Windows 11 flapTop. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  CheckGroup1.Items.Add(DateTimeToStr(Now));end;                        Did you set a constraint? jamie ---------------------------------------------------------------------- LemonParty · 2025-08-10 13:06 wp, I added a scrollbox to your example and behavior of groupbox changed. jamie, no I didn't. ---------------------------------------------------------------------- wp · 2025-08-10 14:58 I see. But when I set Groupbox.AutoSize=true in code (activated the commented-out line at the end) the behaviour is correct again. It was strange, though, that I could not restore the erroneous behaviour any more, i.e. even when I commented out the AutoSize line again I still got the correct behaviour. Only after reloading your original files the error was back. Looking at the lfm file I saw that you are working at a monitor resolution of 192 ppi, my system is at 96 ppi. So, this issue is related to LCL scaling. And indeed, LCL scaling requires special attention when controls are created at runtime. In your system at 192 ppi all dimensions are thought to be valid for this specific resolution. In my code I placed the checkboxes at y positions of 0, 20, 40, 60 and 80 pixels, thinking that this is perfect for my screen at 96ppi where the height of a checkbox is 19 pixels (on Windows). But for 192 ppi, this is way too narrow because the height of a TCheckbox at this resolution should by 2*19 = 38 pixels (+/-). But when the Top positions are scaled manually everything should be fine: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i [...]  with TCheckbox.Create(self) do  begin    Caption := 'This is checkbox 2';  Parent := Groupbox1;    Borderspacing.Left := 12;    BorderSpacing.Right := 12;    Top := Scale96ToForm(20);  end;[...] Scale96ToForm assumes that the provided length argument is valid for 96 ppi and multiplies it by the ratio of the PixelsPerInch of the form to 96. On my system running at 96 ppi, the situation is a bit more complex because during reading of the lfm file the different resolution is detected, and the central scaling procedure AutoAdjustLayout is executed at the end of the of construction process, and in particular after the OnCreate handler where the checkboxes are created. AutoAdjustLayout corrects all dimensions in the ratio of the current resolution to the designtime resolution. While the vertical checkbox positions were correct in the OnCreate handler the following AutoAdjustLayout moved them up by 50% (=96/192) - same result as in your case: overlapping checkboxes... But the solution is the same: When I manually scale the Top positions as shown above, everything is fine (BTW, the Borderspacings should be scaled, too). And why couldn't I restore the error behaviour after uncommenting the "Autoscale" line and then commenting it again? Because the project is saved before running, and and this step the lfm is rewritten with my current screen resolution. Afterwards the dimensions in the file are for 96ppi and the dimensions of the checkboxes are for 96 ppi, too - perfect match. And Scale96ToForm is not harmful either, because it just multiplies dimensions here by 1. ---------------------------------------------------------------------- jamie · 2025-08-10 15:12 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.FormCreate(Sender: TObject);Var  H:Integer;begin  H := Trunc(Canvas.TextHeight('H')*1.25);  with TCheckbox.Create(self) do  begin    Caption := 'Checkbox 1';    Parent := Groupbox1;    Borderspacing.Left := 12;    BorderSpacing.Right := 12;    Top := 0*H;  end;   with TCheckbox.Create(self) do  begin    Caption := 'This is checkbox 2';    Parent := Groupbox1;    Borderspacing.Left := 12;  BorderSpacing.Right := 12;    Top := 1*H;  end;   with TCheckbox.Create(self) do  begin    Caption := 'cb3';    Parent := Groupbox1;    Borderspacing.Left := 12;    BorderSpacing.Right := 12;    BorderSpacing.Bottom := 6;    Top := 2*H;  end;   with TCheckbox.Create(self) do  begin    Caption := 'The checkbox #4';    Parent := Groupbox1;    Borderspacing.Left := 12;    BorderSpacing.Right := 12;    BorderSpacing.Bottom := 6;    Top := 3*H;  end;   with TCheckbox.Create(self) do  begin    Caption := 'and #5';    Parent := Groupbox1;    Borderspacing.Left := 12;    BorderSpacing.Right := 12;    BorderSpacing.Bottom := 6;    Top := 4*H;  end; //  Groupbox1.AutoSize := true;end;                                                  I use the font height because it changes with scaling. ---------------------------------------------------------------------- jamie · 2025-08-10 15:40 a TFlowPanel works well for this. You can adjust it to your choice and easy to add check boxes Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  With TCheckBox.Create(FlowPanel1) do    Begin      Caption := DateTimeTostr(Now);      Parent := FlowPanel1;    end;end;                                     Set the AutoSize to true. jamie ---------------------------------------------------------------------- LemonParty · 2025-08-10 18:27 I have 1 more problem. This is 2 groupboxes that should be rendered 1 below other. Code that creates them is follow: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   gbFilePropertiesToCopy.Left:= 16;  gbFilePropertiesToCopy.Top:= y;  z:= 16;  for o in [wmdofpData..wmdofpAuditingInformation] do begin    CreateCheckBox(o, gbFilePropertiesToCopy, 16, z);    inc(z, TCheckBox(FWOArray[o]).Height + CGap);  end;  inc(y, gbFilePropertiesToCopy.Height + CGap);   gbDirectoryPropertiesToCopy.Left:= 16;  gbDirectoryPropertiesToCopy.Top:= y;  z:= 16;  for o in [wmdodpData..wmdodpSkipAltDataStreams] do begin    CreateCheckBox(o, gbDirectoryPropertiesToCopy, 16, z);    inc(z, TCheckBox(FWOArray[o]).Height + CGap);  end;  inc(y, gbDirectoryPropertiesToCopy.Height + CGap);  Why groupboxes are cuted in middle? ---------------------------------------------------------------------- wp · 2025-08-10 18:45 Where is this code called? In the form's OnCreate? This usually is too early to rely on the size of auto-sized controls because AutoSizing occurs later. The best way to keep the 2nd groupbox below the 1st one, at a given distance, is to use anchoring (https://wiki.freepascal.org/Anchor_Sides). ---------------------------------------------------------------------- LemonParty · 2025-08-10 19:20 Yes, called from OnCreate. I moved it to OnShow and still cuted in half. ---------------------------------------------------------------------- wp · 2025-08-10 21:53 Manually calculating control positions when Autosizing and LCLscaling are involved is very difficult... Use the helpers that the LCL gives you: Anchoring: Use the AnchorSidesLeft/Top/Right/Bottom properties and their subproperties Control and Side to attach controls to each other. At designtime you have the AnchorEditor, at runtime you must call these methods yourself. Read and understand the article that I linked in the previous post.ChildSizing: Made for exactly this purpose, and in fact it is used in TCheckGroup to align the checkboxes in there (BTW: Why don't you use TCheckGroup?): https://wiki.freepascal.org/Aut osize_/_Layout#Rows,_columns_and_linesThe attached demo uses ChildSizing to position the checkboxes within the groupboxes, and Anchoring to position the groupboxes relative to each other. ---------------------------------------------------------------------- Martin_fr · 2025-08-10 23:11 Quote from: LemonParty on August 10, 2025, 09:20:40 pmYes, called from OnCreate. I moved it to OnShow and still cuted in half. There was a very recent fix, that deals with **some** of those effects, when you have - a form loaded from lfm, that will be scaled - then do stuff in the constructor (resize some stuff) - then show the form. So not 100% your case, but close. Currently, the scaling in the above case is done in "AfterConstruction" => So whatever you do in Form.Create is unscaled. If your form was saved with DPI=192, then you add something in Create, and then that addition will be handled like it was put there for 192 dpi. So if that form is then show at a different dpi, then the addition is scaled too. (At least if I remember correctly). But, in cases like that, autosizing may have gotten broken. See commits 09e453027f3a521ce7f80ccba897f8d281fab39d 0da95ac806052c9f7d9f5c20db1a9974074dd010 4cca89e05f3fcc0d7f801a6ce602639fd3c1d1f3 c9a4d44950d87108b2ba51c76b960071d3d60f16 This is only changed in 4.99 (trunk). I haven't tested any of your examples / late now / too tired.