Recent

Author Topic: Form adjusting to screen properties?  (Read 553 times)

RickSpink

  • Newbie
  • Posts: 2
Form adjusting to screen properties?
« on: December 09, 2025, 04:49:33 am »
At the risk of being accused of naivety ...

I have a program which runs in full-screen mode under Linux. There's basically one form with 20-ish controls of various kinds.

Until now it has been used on three machines, all with the same screen resolution. Now it must be made to run on several other machines, of varying specifications.

I have read a lot about changing resolutions and remain confused. I wonder ...

is there a way to design / program the form so that it "magically" adapts to the screen size it is running on? In other words, have the same executable on all machines regardless of their capabilities.

TIA
Rick

Thaddy

  • Hero Member
  • *****
  • Posts: 18700
  • To Europe: simply sell USA bonds: dollar collapses
Re: Form adjusting to screen properties?
« Reply #1 on: December 09, 2025, 07:10:38 am »
You can get and set the necessary information at runtime by using TScreen.
https://lazarus-ccr.sourceforge.io/docs/lcl/forms/tscreen.html
Together with anchors, the AutoSize properties (AutoScaleTransform for charts) you can obtain very good results and you only have to do it once.

Takes a bit of work, but it is not difficult.
Most professionals in Lazarus or Delphi work  like that.
The most difficult part is often to get the fonts right if you intend to work cross-platform or use fonts that are not in the particular OS version.
It helps to  some extend if you application has a fonts dialog and use TScreen.SystemFont as the default. The available fonts are in the TScreen.Fonts property.
« Last Edit: December 09, 2025, 07:28:21 am by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

wp

  • Hero Member
  • *****
  • Posts: 13334
Re: Form adjusting to screen properties?
« Reply #2 on: December 09, 2025, 03:00:56 pm »
[...] full-screen mode under Linux [...]one form with 20-ish controls of various kinds [...] same executable on all machines regardless of their capabilities
Depending on the logical arrangement of the 20+ controls I would add several panels which must be distributed such that their size adjusts to the size of the main form in given ratios (and this adjusts to the size of the monitor due to full-screen mode). The controls then should be anchored inside the corresponding panels so that the control size also grows/shrinks with the size of the panels.

In the attached test project there are 6 panels linked to each other by anchoring. An OnResize event handler is provided to define the size ratios of some of the individual panels. Panel2 (top center) and Panel3 (top right) for example are handled such that their widths are in the ratio 3:1. Controls then are packed into their panels either by aligning (alClient for ShellTreeView in Panel5), ChildSizing (checkboxes in Panel3, Labels&Edits in Panel1), or anchoring (ListBox in Panel1).

If you never heard of ChildSizing: Read this. AnchorSides is explained in https://wiki.freepascal.org/Anchor_Sides.

RickSpink

  • Newbie
  • Posts: 2
Re: Form adjusting to screen properties?
« Reply #3 on: December 10, 2025, 08:11:59 am »
Thanks WP and Thaddy. That gives me a great leg-up.

Maybe WPs work as an example sould be in the wiki somewhere?

Rick

 

TinyPortal © 2005-2018