Delphi - 在左侧监视器上打开表格

Delphi - open form on left monitor

我希望我的应用程序始终在左侧显示器上启动(以防连接的显示器超过 1 个)。

如何做到这一点?如何检测左显示器编号?

感谢您的帮助!

我们使用这个代码片段:

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;

那么_MonitorNum就是最左边的显示器编号。

FMX 应用程序在屏幕和显示器上的行为会有所不同

下面的代码有点fiddle我在Form Show上使用的是将表单对齐到当前鼠标所在屏幕的左上角。

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;