Recent

Author Topic: DPI and Form  (Read 3244 times)

Przemyslav

  • New Member
  • *
  • Posts: 44
DPI and Form
« on: March 22, 2017, 09:30:50 pm »
I am developing a program that I develop in 100% 96 dpi and when running the product on different dpi all my controls get messy and go out of the regular places and fonts in buttons, panels gets bigger and the product looks ugly. Is there a function / solution that can be set on each form.oncreate to encounter this and always display the product on each of the dpi settings in Windows as it was developed under? Or maybe some solution to stop this?

Thanks for help :)

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: DPI and Form
« Reply #1 on: March 22, 2017, 10:04:01 pm »
1) On each form OnCreate call, this works on 1.6.4:

Code: Pascal  [Select][+][-]
  1.  Self.AutoAdjustLayout(lapAutoAdjustForDPI, 96, Screen.PixelsPerInch, Self.Width, ScaleX(Self.Width, 96));

And this should work in older lazarus that has AutoAdjustLayout implemented, I don't remember exactly from which release that was added. More or less parameters, but works the same.

2) And in Project Options depending on your Lazarus version enable High DPI settings (DPI Awareness).

I've added this to the wiki
http://wiki.lazarus.freepascal.org/High_DPI#High_DPI_in_older_Lazarus

Please add the format tag someone is reading this. People still using 1.6.x and 1.8 is not ready yet.

Przemyslav

  • New Member
  • *
  • Posts: 44
Re: DPI and Form
« Reply #2 on: March 24, 2017, 08:37:43 pm »
Thank you very much ;) It's work :)

creaothceann

  • Full Member
  • ***
  • Posts: 117
Re: DPI and Form
« Reply #3 on: March 25, 2017, 11:10:49 pm »
Code: Pascal  [Select][+][-]
  1.  Self.AutoAdjustLayout(lapAutoAdjustForDPI, 96, Screen.PixelsPerInch, Self.Width, ScaleX(Self.Width, 96));

Could be done like this:

Code: Pascal  [Select][+][-]
  1. procedure Adjust_DPI(const Form : TForm);  inline;
  2. begin
  3. with Form do  AutoAdjustLayout(lapAutoAdjustForDPI, DesignTimeDPI, Screen.PixelsPerInch, Width, ScaleX(Width, DesignTimeDPI));
  4. end;

...which would be called in the form's OnCreate as Adjust_DPI(Self).

(Needs units Controls, Forms, Graphics)
« Last Edit: March 25, 2017, 11:13:51 pm by creaothceann »

 

TinyPortal © 2005-2018