Recent

Author Topic: save form position  (Read 2875 times)

Hansvb

  • Hero Member
  • *****
  • Posts: 618
save form position
« on: April 17, 2015, 09:19:57 pm »
How to safe the form position when the number of monitors is diffferent.

When i just safe the left and top position it goes wrong when you safe on a 2 monitor  system and start on a 1 monitor system.
The left is then -1920 (example)

Hansvb

  • Hero Member
  • *****
  • Posts: 618
Re: save form position
« Reply #1 on: April 17, 2015, 09:48:02 pm »
This seems to work:

Code: [Select]
      Left := ReadInteger('Position', 'Frm_Main_Left', 0);
      Top  := ReadInteger('Position', 'Frm_Main_Top' , 20);
      //1 of 2 monitoren (prog kan anders buiten beeld raken)

       i := Screen.MonitorCount;
       if (Left < 0) and
          (i = 1) then
            Left := 20;

       if left > screen.Monitors[i-1].width -50 then
            Left := 20; 

Chronos

  • Full Member
  • ***
  • Posts: 241
    • PascalClassLibrary
Re: save form position
« Reply #2 on: April 18, 2015, 02:19:07 pm »
I think form position is relative to entire desktop (Screen.DesktopRect). So it should be sufficient to check if form is at least partial visible inside desktop rectangle.

I created wiki page related to storing form position and size: wiki.freepascal.org/Remember_form_position_and_size
There we can collect useful information related to topic.

For example I was not aware of possibility to store position using TForm.SessionProperties. This is interesting approach. But to have more robust position and size handling rather custom components should be created for such task. For example TForm.Restored properties can be kept with such method they are readonly. Same is valid for WindowState which can be set also to wsMinimized and in such case form position can be restored incorrectly or user could want to not keep minimized stat at all, just normal and maximized.

There are also some Delphi components available for example here: http://www.torry.net/pages.php?id=96

 

TinyPortal © 2005-2018