Recent

Author Topic: Changing widths of components in code with High DPI  (Read 1000 times)

stem

  • Jr. Member
  • **
  • Posts: 88
Changing widths of components in code with High DPI
« on: October 09, 2019, 10:31:40 pm »
Hi,

in my project (96 dpi) I'm changing the width of a component according to the width of the form, for example:

Code: Pascal  [Select][+][-]
  1. hdiff := Form1.Width - 700;
  2. LabeledEdit1.Width := 344 + hdiff;

700 is the width of the form at "normal size". 344 is the width of the component at "normal size" of the form.

When I enable High DPI in the project options, the width of the component gets far too high.

How can I adjust my code so that it is compatible with other DPI values than 96?

Thank you!


stem

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Changing widths of components in code with High DPI
« Reply #1 on: October 09, 2019, 11:36:01 pm »
Hi,

in my project (96 dpi) I'm changing the width of a component according to the width of the form, for example:

Code: Pascal  [Select][+][-]
  1. hdiff := Form1.Width - 700;
  2. LabeledEdit1.Width := 344 + hdiff;

700 is the width of the form at "normal size". 344 is the width of the component at "normal size" of the form.

When I enable High DPI in the project options, the width of the component gets far too high.

How can I adjust my code so that it is compatible with other DPI values than 96?

Thank you!


stem

 I don't understand why you are subtracting - 700 from the width ?
The only true wisdom is knowing you know nothing

stem

  • Jr. Member
  • **
  • Posts: 88
Re: Changing widths of components in code with High DPI
« Reply #2 on: October 10, 2019, 09:20:55 am »
The width of the form at design time is 700 pixels. If the width gets wider at runtime, let's say to 710 pixels, the additional 10 pixels are added to the width of the component so that the component can use the additional horizontal space.

I know there is the align property, but I have a complex layout and do not want to use align. With 96 DPI everything works fine this way.


stem

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Changing widths of components in code with High DPI
« Reply #3 on: October 10, 2019, 09:42:24 am »
Did you activate LCL scaling (in the project options)? It will rescale the form and all its components such that it works correctly at different resolutions. The is no need to calculate anything manually.

And I urge you to use the Anchor Editor to layout the forms, in particular when the layout is complex. It is the only guarantee that the layout is still correct when you switch from Windows to Linux or Mac, or translate the application - due to the different text lengths.

P.S.
TLabeledEdit does not work properly with the AnchorEditor - use separate TLabel and TEdit controls instead.

 

TinyPortal © 2005-2018