Chris
Chris

Reputation: 364

Delphi - open form on left monitor

I want my application to always start on the left monitor (in case that there are more than 1 connected).

How can this be done? How to detect the left monitor number?

Thanks for helping!

Upvotes: 1

Views: 1857

Answers (2)

Andre Van Zuydam
Andre Van Zuydam

Reputation: 799

FMX Applications will behave differently for Screens & Displays

The code below is a little fiddle I used on Form Show to align the form to the top left of the screen of where the mouse is currently found.

var
  currentDisplay: TDisplay;
  mousePosition: TPointF;

begin
  if (Screen.DisplayCount > 0) then
  begin
    mousePosition := Screen.MousePos;
    currentDisplay := Screen.DisplayFromPoint(mousePosition);
    Left := (currentDisplay.PhysicalBounds.Left);
    Top := 0;
  end;
end;

Upvotes: 0

penarthur66
penarthur66

Reputation: 321

We use this code fragment:

if Screen.MonitorCount > 1 then
begin
  MonList := TList<TMonitor>.Create;

  for I := 0 to Screen.MonitorCount - 1 do
    MonList.Add(Screen.Monitors[I]);

  // sort by screen.monitor.left coordinate
  MonList.Sort(TComparer<TMonitor>.Construct(
    function(const L, R: TMonitor): Integer
    begin
      Result := L.Left - R.Left;
    end));

  _MonitorNum := TMonitor(MonList[0]).MonitorNum;

  // free the list
  MonList.Destroy;
end;

Then _MonitorNum holds the number of the left most monitor.

Upvotes: 1

Related Questions