Recent

Author Topic: [SOLVED] Windows only issue, invicible border  (Read 308 times)

Handoko

  • Hero Member
  • *****
  • Posts: 5427
  • My goal: build my own game engine using Lazarus
[SOLVED] Windows only issue, invicible border
« on: February 28, 2025, 01:56:28 pm »
Today I am writing a small Windows tool on a Windows 11 laptop.
Try this code on your Windows computer:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Left := 0;
  4.   Top := 0;
  5. end;

I am a Linux user, I am not sure but I believe this behavior only happens on Windows 8 and above. After running the code above and clicking the button, the form won't move to the exact top left corner we expected. Here is an old discussion related with this issue:
https://forum.lazarus.freepascal.org/index.php/topic,65298.msg497415.html#msg497415

Does anybody know how to make the code above to work correctly on WinXP to Windows 11? Or how to detect the thickness of the invincible border?
« Last Edit: March 01, 2025, 08:03:13 am by Handoko »

BrunoK

  • Hero Member
  • *****
  • Posts: 698
  • Retired programmer
Re: Windows only issue, invicible border
« Reply #1 on: February 28, 2025, 04:02:59 pm »
Try this :
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls
  9.   {$IFDEF WINDOWS}
  10.   ,Windows
  11.   {$ENDIF WINDOWS}
  12.   ;
  13.  
  14. type
  15.  
  16.   { TForm1 }
  17.  
  18.   TForm1 = class(TForm)
  19.     Button1: TButton;
  20.     procedure Button1Click(Sender: TObject);
  21.   private
  22.     FFormXOffset: integer;
  23.   public
  24.  
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. { TForm1 }
  35.  
  36. procedure TForm1.Button1Click(Sender: TObject);
  37. var
  38.   lPoint: TPoint;
  39. begin
  40.   {$IFDEF WINDOWS}
  41.   lPoint.SetLocation(0, 0);         // Init lPoint to TopLeft of form
  42.   lPoint:= ClientToScreen(lPoint);  // Retrieve screen coord of form
  43.   FFormXOffset := Left - lPoint.X;  // Compute offset relative to declared left.
  44.   {$ENDIF WINDOWS}
  45.   Left := FFormXOffset + { Desired real left } 0; // Apply offset to desired position
  46.   Top := 0;
  47. end;
  48.  
  49. end.

Handoko

  • Hero Member
  • *****
  • Posts: 5427
  • My goal: build my own game engine using Lazarus
Re: Windows only issue, invicible border
« Reply #2 on: March 01, 2025, 08:01:39 am »
Yes, it work. Thank you very much. The code may look simple but very helpful. I learned something new today.

 

TinyPortal © 2005-2018