Recent

Author Topic: High DPI Development - Knowledge share  (Read 117 times)

zgabrovski

  • New Member
  • *
  • Posts: 18
High DPI Development - Knowledge share
« on: April 02, 2020, 03:40:56 pm »
Dear all,
A day ago I fjust inished my LCL project development and decide to test it how it works under HighDpi (scale to 125% of screen size under Win64, 7/10).
A have a lot of session properties in forms that save form width and height and also some controls width, heigh and positions.
I was negatively surprised than in this mode every time when I open a form with width and height saved through Session property of the form, it increases it width and  it becomes lagreg and larger.

So, the problem was that in HighDPI Mode LCL automatically resize form Width and Height based on form PixelsPerInch property,
If the form if load from the resource all the time, there is no problem - it loads a naively defined width and height in design time  and multiply by PixelsPerInch/96 to resize it in Large font mode.
But if you save the form width and/or  height (or any other screen component coordinates or width/height) with form session property and TPropertyStorage descendant control, it saves new, scaled propertis. Next time when you open the form in will become larger and so on.

So the solution is:
Put event handler on TPropertyStorage "OnRestore" event;

in the event handler, put the following (sample code):

procedure Tfsettle.FormStorage1RestoreProperties(Sender: TObject);
begin
grpbReservations.Width := ScaleScreenTo96( grpbReservations.Width );
pnlSettledGuest.Width := ScaleScreenTo96( pnlSettledGuest.Width );
end;

And this will solve the case.

Another Hint: Do not develop under HighDPI Mode, always develop under normal mode and only test under HighDPI.
Otherwise Lazarus IDE will set DesignTimePPI of the different forms to different values.

Please, excuse me for the poor English :)

BR,
Zdravko





 

TinyPortal © 2005-2018