Delphi-左监视器上的打开窗体

Delphi-左监视器上的打开窗体,delphi,multiple-monitors,Delphi,Multiple Monitors,我希望我的应用程序始终在左侧监视器上启动(如果连接了多个监视器) 如何做到这一点?如何检测左监视器编号 谢谢你的帮助 我们使用以下代码片段: 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

我希望我的应用程序始终在左侧监视器上启动(如果连接了多个监视器)

如何做到这一点?如何检测左监视器编号


谢谢你的帮助

我们使用以下代码片段:

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;
如果Screen.MonitorCount>1,则
开始
MonList:=TList.Create;
对于I:=0到Screen.MonitorCount-1 do
MonList.Add(Screen.Monitors[I]);
//按screen.monitor.left坐标排序
MonList.Sort(TComparer.Construct(
函数(常数L,R:TMonitor):整数
开始
结果:=L.左-R.左;
(完),;
_MonitorNum:=TMonitor(MonList[0])。MonitorNum;
//释放列表
毁灭;
结束;

然后_MonitorNum保存最左边监视器的编号。

在询问之前,您应该在网上搜索-您不想让用户自行选择首选哪个监视器和位置的任何特定原因?我希望您的卸载程序运行良好tested@CraigYoung像这样的东西对室内来说很有意义应用。不管怎样,我可能只是把表单位置存储在注册表中。@Craig你说得对,台式计算机记住表单位置是一个更好的解决方案,但它是一个笔记本,我在不同的扩展底座上使用不同的显示器设置。在这种情况下,我认为记住这个位置不会做创建列表类、anon方法、sort等实例所需的技巧。只需在监视器上运行并确定最左边的一个<代码>变量最小值,最小索引:整数。。。MinValue:=屏幕。监视器[0]。左侧;最小指数:=0;对于i:=1 to Screen.MonitorCount-1 do if Screen.Monitors[i]。Left当循环终止时,
MinIndex
标识最左边的监视器。@David这是真的。