pyscripter 689 Posted September 27, 2020 (edited) TControl.SetParent contains the following code: if not (csLoading in ComponentState) and not (csDesigning in ComponentState) and not (csDestroying in ComponentState) and not (csFreeNotification in ComponentState) then begin if not (csDesigning in Parent.ComponentState) then ScaleForPPI(GetParentCurrentDpi); end; Apart from the fact that I would write the if condition as if [csLoading, csDesigning, csDestroying, csFreeNotification] * ComponentState = [] then does anyone have any idea why controls with csFreeNotification are not scaled? This makes writing per Monitor DPI aware applications much harder. Edited September 27, 2020 by pyscripter Share this post Link to post
Uwe Raabe 2057 Posted September 27, 2020 You are not alone: Parented controls with free notifications aren't scaled Frame with Assigned PopupMenu is wrong Displayed on high DPI A scaled form gets resized to design time ClientWidth/ClientHeight when embeded in a parent form 1 1 Share this post Link to post
pyscripter 689 Posted September 27, 2020 (edited) @Uwe Raabe Thanks! Good to know I am not the only one bitten by this (should have checked QA), but bad to know it has not been fixed for quite some time now. I placed my vote on the first issue. You can work around the bug by manually calling ScaleForPPI(future parent PPI) before setting the parent but it gets difficult to get right with things like docking. Embarcadero will face this issue when they try to make the IDE per monitor DPI-aware as promised. Edited September 27, 2020 by pyscripter Share this post Link to post
pyscripter 689 Posted September 27, 2020 (edited) This is another tough one to work around: procedure TCustomForm.ScaleForPPIRect(NewPPI: Integer; NewRect: PRect); var LCurrentPixelsPerInch: Integer; I: Integer; PriorHeight: Integer; begin if not (csDesigning in ComponentState) and ((not HandleAllocated and (Parent <> nil)) or (NewPPI < 30)) then Exit; Parented forms with unallocated handle are not scaled (e.g. page-like controls). It becomes even harder since TCustomForm.SetParent destroys the handle if the form had no parent. This is irrespective of FreeNotifications. Edited September 27, 2020 by pyscripter Share this post Link to post
Vincent Parrett 750 Posted September 27, 2020 4 hours ago, Uwe Raabe said: You are not alone: Parented controls with free notifications aren't scaled Frame with Assigned PopupMenu is wrong Displayed on high DPI A scaled form gets resized to design time ClientWidth/ClientHeight when embeded in a parent form 🤦♂️ Oh FFS - how many versions do we have to wait for properly functioning high dpi support. The fact that these were reported 3 or 4 years ago and have not been addressed is astounding. Surely if you are working on high dpi support you would look at these issues in your own bug tracking system. Share this post Link to post
pyscripter 689 Posted September 27, 2020 The workaround for both issues is to follow a pattern such as this: Form.SetParent(Panel); Form.HandleNeeded; Form.ScaleForPPI(Panel.CurrentPPI); 2 Share this post Link to post