Recent

Author Topic: Strange behavior of the TForm.Left property  (Read 1445 times)

Unvictis

  • New Member
  • *
  • Posts: 21
  • Nihil habeo, nihil timeo
Strange behavior of the TForm.Left property
« on: June 10, 2025, 11:24:16 am »
Hello!

Why is it that when I specify the Left = 0 position in the properties for the TForm shape, the shape has an indentation significantly greater than zero pixels (about 7 pixels). At the same time, for Top = 0, everything works as intended.

Windows 10 22H2 x64, Lazarus 2.0.8 x86, Lazarus 4.0 x86
« Last Edit: June 10, 2025, 11:47:20 am by Unvictis »

VisualLab

  • Hero Member
  • *****
  • Posts: 693
Re: Strange behavior of the TForm.Left property
« Reply #1 on: June 10, 2025, 11:51:29 am »
I confirm, this is indeed the case. I am using: Windows 10 64-bit, Lazarus 3.8 64-bit.

Unvictis

  • New Member
  • *
  • Posts: 21
  • Nihil habeo, nihil timeo
Re: Strange behavior of the TForm.Left property
« Reply #2 on: June 10, 2025, 02:33:04 pm »
To check, I made additional applications on Delphi 2, 4, 7 and ran them on Windows 95, XP, 7, 10. This bug appears only under Windows 10, regardless of the Delphi/Lazarus version. I think this is a problem (feature) of Windows 10.

Zvoni

  • Hero Member
  • *****
  • Posts: 3165
Re: Strange behavior of the TForm.Left property
« Reply #3 on: June 10, 2025, 02:35:55 pm »
Maximize your Form and read out the Left-Property.
Does it return "0" or a negative value?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

n7800

  • Hero Member
  • *****
  • Posts: 583
  • Lazarus IDE contributor
    • GitLab profile
Re: Strange behavior of the TForm.Left property
« Reply #4 on: June 10, 2025, 02:40:26 pm »
I checked on Windows 7 and 8.1, and everything is fine.

But I think it's not the version, but the theme. I have them disabled (for performance), but on your screenshot there is a half-shadow around the window. Maybe it is taken into account? You can try to disable them in the OS settings, if you don't mind rebooting your PC.



But you can check how it works at run-time. Try to run the application with this event:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   Left := 0;
  4. end;
  5.  

is it displayed at the edge? Now try to disable "Use manifest resource (and enable themes)" in the project options (see the attached screenshot) and run it again.

Unvictis

  • New Member
  • *
  • Posts: 21
  • Nihil habeo, nihil timeo
Re: Strange behavior of the TForm.Left property
« Reply #5 on: June 10, 2025, 02:52:30 pm »
Maximize your Form and read out the Left-Property.
Does it return "0" or a negative value?
When i maximize form Left value is -8.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11911
  • Debugger - SynEdit - and more
    • wiki

Zvoni

  • Hero Member
  • *****
  • Posts: 3165
Re: Strange behavior of the TForm.Left property
« Reply #7 on: June 10, 2025, 03:53:14 pm »
What i could find out, it has apparently to do with BorderStyle in combination with Win10-Themes
n7800 idea to disable "Use manifest resource (and enable themes)" in Project-Options makes no difference
And Martin pretty much confirms it with the Link to the GitLab-Issue
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Unvictis

  • New Member
  • *
  • Posts: 21
  • Nihil habeo, nihil timeo
Re: Strange behavior of the TForm.Left property
« Reply #8 on: June 10, 2025, 05:35:26 pm »
Thank you, friends, for your quick response and for your lively participation in my question!

Based on the above, I came to the conclusion that this error is not in the Lazarus LCL / Delphi VCL code, but rather in the incorrectly displayed actual Windows 10 windows (https://superuser.com/questions/1098708/is-it-possible-to-turn-visible-the-invisible-windows-borders-of-windows-10).

Now I'm thinking about methods to compensate for this distance when calculating the position of the form (after checking the type and version of the system), for example: Form1.Left := 0 - deltaX , where deltaX is the system width of the window border. The question arises, how to get it correctly? Via GetSystemMetrics from WinAPI? In this case, which constant should I use correctly (SM_CXSIZEFRAME, SM_CXFOCUSBORDER, SM_CXFRAME or another)?

n7800

  • Hero Member
  • *****
  • Posts: 583
  • Lazarus IDE contributor
    • GitLab profile
Re: Strange behavior of the TForm.Left property
« Reply #9 on: June 10, 2025, 08:26:18 pm »
I've been trying to find a Microsoft article where I read a long time ago about this (shadow, client area, rounded corners and other window effects), but I couldn't find it.

But in the process of searching I came across some answers to your question:
https://stackoverflow.com/questions/32159675/retrieve-window-size-without-windows-shadows

Thaddy

  • Hero Member
  • *****
  • Posts: 18502
  • Here stood a man who saw the Elbe and jumped it.
Re: Strange behavior of the TForm.Left property
« Reply #10 on: June 11, 2025, 06:19:15 am »
You were probably searching for an article by Raymond Chen?
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

Unvictis

  • New Member
  • *
  • Posts: 21
  • Nihil habeo, nihil timeo
Re: Strange behavior of the TForm.Left property
« Reply #11 on: June 11, 2025, 06:53:45 am »
Thank you all for trying to figure out my question. The topic probably goes beyond the Lazarus forum, so I'll try to look for answers in the WinAPI documentation. The topic can be closed.

Unvictis

  • New Member
  • *
  • Posts: 21
  • Nihil habeo, nihil timeo
Re: Strange behavior of the TForm.Left property
« Reply #12 on: June 11, 2025, 08:31:28 am »
You were probably searching for an article by Raymond Chen?
I found this article: https://devblogs.microsoft.com/oldnewthing/20150304-00/?p=44543

n7800

  • Hero Member
  • *****
  • Posts: 583
  • Lazarus IDE contributor
    • GitLab profile
Re: Strange behavior of the TForm.Left property
« Reply #13 on: June 11, 2025, 10:38:24 am »
You were probably searching for an article by Raymond Chen?
I found this article: https://devblogs.microsoft.com/oldnewthing/20150304-00/?p=44543

Unfortunately, no. If I remember correctly, it was a fairly large page from the documentation (MSDN), not just an article.

n7800

  • Hero Member
  • *****
  • Posts: 583
  • Lazarus IDE contributor
    • GitLab profile
Re: Strange behavior of the TForm.Left property
« Reply #14 on: June 11, 2025, 10:50:19 am »
There was something like these pages (just an example):
* https://learn.microsoft.com/en-us/windows/apps/design/layout/depth-shadow
* https://learn.microsoft.com/en-us/windows/win32/dwm/customframe
but it was written in detail about borders/shadows and a WinAPI function for working with them.

 

TinyPortal © 2005-2018