在Delphi 7中使用TScreen

Ruu*_*itz 7 delphi delphi-7

我的Delphi-7应用程序显示:

Screen.DesktopWidth  
Screen.DesktopHeight  
Screen.Monitors[0].Width  
Screen.Monitors[0].Height  
Run Code Online (Sandbox Code Playgroud)

并且,如果选择了第二台显示器,还:

Screen.Monitors[1].Width  
Screen.Monitors[1].Height  
Run Code Online (Sandbox Code Playgroud)

随着应用程序在我的WinXP-Pro PC上运行,我转到控制面板/显示/设置,并更改第二台显示器的设置(添加或删除它).

然后,我单击"刷新"按钮以显示4(或6)个参数的新值,并发生意外情况:Screen.DesktopWidth和Screen.DesktopHeight显示正确的新值,但其他2(或4)的值参数非常错误.

像Screen.Monitors [0] .Width = 5586935,而它应该是1680.

在Delphi 7中使用TScreen是否有一些特殊规则?

Ruu*_*itz 0

感谢 TLama,我在 Delphi 7 中找到了 TScreen 问题的解决方法。

“导致”问题的原始代码:

LabMon1.Caption := ' Mon 1: ' + IntToStr (Screen.Monitors[0].Width) +
                   ' x ' + IntToStr (Screen.Monitors[0].Height);

if (Screen.MonitorCount = 1)
then LabMon2.Caption := ' Mon 2: -'
else LabMon2.Caption := ' Mon 2: ' + IntToStr (Screen.Monitors[1].Width) +
                        ' x ' + IntToStr (Screen.Monitors[1].Height);
Run Code Online (Sandbox Code Playgroud)

我只需要添加 1 行代码就可以解决它:

LabMon1.Caption := ' Mon 1: ' + IntToStr (Monitor.Width) +
                   ' x ' + IntToStr (Monitor.Height) ;

LabMon1.Caption := ' Mon 1: ' + IntToStr (Screen.Monitors[0].Width) +
                   ' x ' + IntToStr (Screen.Monitors[0].Height);

if (Screen.MonitorCount = 1)
then LabMon2.Caption := ' Mon 2: -'
else LabMon2.Caption := ' Mon 2: ' + IntToStr (Screen.Monitors[1].Width) +
                        ' x ' + IntToStr (Screen.Monitors[1].Height);
Run Code Online (Sandbox Code Playgroud)

再次感谢 TLama,您对这个问题线程做出的巨大贡献!

  • 不客气!实际上,您不需要使用“Monitor.Width”或“Monitor.Height”或在某处分配它们的值。只需*触摸* [`Monitor`](http://docwiki.embarcadero.com/Libraries/en/Vcl.Forms.TCustomForm.Monitor) 属性就足够了,当句柄时,其 getter 会更新 `Screen.Monitors` 列表在该列表中找不到主监视器的名称。我用它来检查宽度。如果你很幸运并且编译器没有消除这样的语句,那么仅使用“Monitor;”可能就足够了,这可能会迫使 getter 执行我所描述的操作。但无论如何,它仍然很脏。 (3认同)