如何选择要打开应用程序的显示器?

Jlo*_*uro 6 delphi multiple-monitors

可能重复:
在第二台显示器上启动程序?

我有两个显示器连接到我的笔记本电脑的显示器.如何选择应用程序显示的显示器?

另外,如何检测我连接的显示器数量,以便我可以选择一个?

谢谢

And*_*and 6

使用该Screen对象.

获取监视器计数

ShowMessage(IntToStr(Screen.MonitorCount))
Run Code Online (Sandbox Code Playgroud)

获取显示器细节

Screen.Monitors[i].Left (integer)
                  .Top (integer)
                  .Width (integer)
                  .Height (integer)
                  .BoundsRect (TRect)
                  .WorkareaRect (TRect)
                  .Primary (boolean)
Run Code Online (Sandbox Code Playgroud)

其中i是监视器的索引,即i = 0,1,...,Screen.MonitorCount - 1.

因此,例如,要使表单占据整个第i个监视器,请使用

BoundsRect := Screen.Monitors[i].BoundsRect; // or you could make the rect smaller
WindowState := wsMaximized; // possibly
Run Code Online (Sandbox Code Playgroud)

  • 当然,对于非常简单的情况,设置`DefaultMonitor`属性可能足以满足需要. (4认同)