Search code examples
delphidelphi-xe2multiple-monitors

Delphi: handling multiple monitors and TForm.Left relative property


As i show a form i display it where it was last time using TForm.Left property i saved on ini file.

I'd like to add support for multiple monitors, because in case of 2 monitors Left can be 2500, so the 2 monitors are seen a a single very wide monitor.

I'd like to save to ini file the monitor number (TForm.Monitor.MonitorNum) but to save the relative Left. Is there a property that tells Left according to monitor?

e.g. i have 2 1024x768 monitors, one on the right (main) and one on the left (secondary/extended), if i move a form on the right monitor 2 pixels from the left the Left property is 1026. I'd like to say "this is monitor 2 and left is 2".

Thanks.


Solution

  • There's no property of TForm that tells its relative position to the monitor it's on. You have to subtract: Left - Monitor.Left . In your example that would be 1026 - 1024.

    Regardless, I don't see any advantage to this approach compared to storing/setting only the left of the form (i.e. 1026). You can use MakeFullyVisible if your concern is monitor arrangement may change between sessions.