Recent

Author Topic: [SOLVED] How to capture window position?  (Read 461 times)

Slyde

  • Full Member
  • ***
  • Posts: 152
[SOLVED] How to capture window position?
« on: February 16, 2023, 12:58:47 am »
I have a main form with a toolbar that, depending on what the user selects, can open multiple smaller windows.  Now, when multiple windows come up and the user takes the time to size and position them on the screen just so, I want those windows to go back to the same positions the next time the user makes that selection.  But I can't figure it out.

I pulled up all the methods from code completion, looked at all the properties in the property manager, but nothing.  I was hoping for something like GetPosition. Something with X/Y coordinates.  Nothing.  I did find Position, but that's not the ticket either.

I need two things:
  1. the means to capture the screen position of the form, and
  2. how to use that to set the forms again


Right now I'm reading/writing to an *.ini file, saving the forms' sizes.  I just don't know how to position them to the same positions the user had them.
« Last Edit: February 16, 2023, 02:05:29 am by Slyde »
Linux Mint 21.3
Lazarus 3.0

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: How to capture window position?
« Reply #1 on: February 16, 2023, 01:33:39 am »
Form.Left & Form.Top are the positions on screen of Form.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

dbannon

  • Hero Member
  • *****
  • Posts: 2786
    • tomboy-ng, a rewrite of the classic Tomboy
Re: How to capture window position?
« Reply #2 on: February 16, 2023, 01:34:01 am »
Every form has a 'top', 'left', height and width property. Save those values to a config file. I tend to use ini files for such things but call then cnf to avoid offending the *nix users.  There is a ini file unit, it does most of the hard work.

Do check the values before you reuse them, if the user has switched monitors for example, you might be trying to display a window outside its viewable area.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Slyde

  • Full Member
  • ***
  • Posts: 152
Re: How to capture window position?
« Reply #3 on: February 16, 2023, 02:05:06 am »
Much thanks, dbannon and KodeZwerg. 
Linux Mint 21.3
Lazarus 3.0

 

TinyPortal © 2005-2018