我的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是否有一些特殊规则?
感谢 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,您对这个问题线程做出的巨大贡献!