Correct events to restore width/height with non-default DPI lazarus / 21-General ---------------------------------------------------------------------- anse · 2025-03-27 08:51 I'm still having some confusion with restoring the width and height of a form, especially when the form has DesignTimePPI=120 (not 96), and the app runs on a different DPI setting. Currently I am storing a user-defined size of a form in the OnDestroy event of a form: 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 TMyForm.FormDestroy(Sender: Tobject);begin  SaveToJson('TMyForm.Width', ScaleFormToDesign(Width));  SaveToJson('TMyForm.Height', ScaleFormToDesign(Height));end; procedure TMyForm.FormCreate(Sender: TObject);begin  // Restoring size  Width := ReadFromJson('TMyForm.Width');  Height := ReadFromJson('TMyForm.Height');end;  Is that the right approach when I want to support DPI scaling across platforms, plus consider a value in TMyForm.DesignTimePPI <> 96? Does it make a difference whether I store the width/height on OnDestroy or OnClose - or in other words - is a form "DeScaled" in OnDestroy? I guess no. ---------------------------------------------------------------------- anse · 2025-03-29 16:03 To answer my own question: yes, that approch is working correctly. Here's a screen of a test project * designed on Windows @120ppi * then copied to my Linux box * built with /usr/bin/lazbuild (without touching the form properties) * then running on Linux @96ppi. Observations: * DesignTimePPI is 120, and never changes at runtime * PixelsPerInch was 120 at designtime, changes at runtime to the value of Screen.PixelsPerInch * FormCreate sets width and height to 500px (still in 120ppi as designed!) * LCL scaling takes place (where exactly?) * in FormShow, the width is now 400px (96ppi) * In FormDestroy the form is not descaled as I suspected * Instead, storing the width for the next session using ScaleFormToDesign(Width) scales it up from 400px to 500px * Next time the app runs it sets the width again to 500px, and the scaling again decreases that to 400px Just feels a bit wrong to store dimensions in the scaling the developer dictates, instead of the actual user scaling. But that's rather philosophic I suppose.