[Lazarus] How to make a TStaticText control appear on top of the form?

Bo Berglund bo.berglund at gmail.com
Sat Feb 13 21:11:04 CET 2021


On Thu, 04 Feb 2021 18:43:55 +0100, Bo Berglund via lazarus
<lazarus at lists.lazarus-ide.org> wrote:

>On Wed, 03 Feb 2021 14:36:38 +0100, Bo Berglund via lazarus
><lazarus at lists.lazarus-ide.org> wrote:
>
>>Very strange, the same binary behaves differently on two HP laptops both running
>>Windows 10 and both a little more than one year old.
>>
>>How can I force these controls on top of the form so they are always visible?
>>
>
>So I found out what causes this to happen:
>
>On my laptop the screen setting is 100%, whereas on the other laptop it is at
>125%.
>Changing that laptop back to 100% makes the missing controls appear on this
>laptop too.
>
>Question:
>---------
>How come some Lazarus controls cannot display on Windows 10 if the screen is set
>to 125% sizing? Is this by design or is it just overlooked?
>
>The monitor is 1920x1080.
>

While hunting this problem I discovered that the TStaticText controls set to
anchor right and top actually were placed erroneously on the form if the program
is executed on a Win10 PC with the display set at 125% when the applicaton was
created on a PC with display at 100%.

So the two controls should be placed on top and right on the main form and this
is where they are displayed on a PC with display set to 100%.
But when I set the display to 125% they move left a distance that makes them
invisible!!!
By adding this code to the function that creates the form transparency shape I
get the controls to display correctly in both 125% and 100% modes.

    stxClose.Left := Self.Width - stxClose.Width;
    stxSize.Left := stxClose.Left - stxSize.Width;

To me it looks like this is a bug in Lazarus (or Fpc).

It seems like when the form is created in Lazarus and alignment is set to
[akTop,akRight] the location of the controls is somehow stored in the executable
as pixels.
Then when the application starts on a PC with 125% Lazarus/Fpc adjusts the form
size and thus also the positions and sizes of all components on the form
accordingly.
But the left property of TStaticText is apparently not adjusted so it uses the
smaller value from the 100% development PC rather than the bigger value on the
125% PC.

The result of this is that the components start out at a location well to the
left of the intended position. And in my case they move into the invisible
transparent part of the form...

Lazarus 2.0.10, Fpc 3.2.0 on Windows 10 x64


-- 
Bo Berglund
Developer in Sweden



More information about the lazarus mailing list