Windows 屏幕保护程序多显示器问题
我编写了一个简单的屏幕保护程序,已将其部署到我们公司的所有客户端 PC 上。
由于我们的大多数电脑都有双显示器,因此我注意确保屏幕保护程序在两个显示器上运行。
这工作正常,但是在某些系统上,主屏幕已交换(到左侧显示器),屏幕保护程序仅在左侧(主)屏幕上工作。
有问题的代码如下。任何人都可以看到我做错了什么,或者有更好的处理方法吗?
作为信息,“this”的上下文是屏幕保护程序表单本身。
// Make form full screen and on top of all other forms
int minY = 0;
int maxY = 0;
int maxX = 0;
int minX = 0;
foreach (Screen screen in Screen.AllScreens)
{
// Find the bounds of all screens attached to the system
if (screen.Bounds.Left < minX)
minX = screen.Bounds.Left;
if (screen.Bounds.Width > maxX)
maxX = screen.Bounds.Width;
if (screen.Bounds.Bottom < minY)
minY = screen.Bounds.Bottom;
if (screen.Bounds.Height > maxY)
maxY = screen.Bounds.Height;
}
// Set the location and size of the form, so that it
// fills the bounds of all screens attached to the system
Location = new Point(minX, minY);
Height = maxY - minY;
Width = maxX - minX;
Cursor.Hide();
TopMost = true;
I have a simple screensaver that I've written, which has been deployed to all of our company's client PCs.
As most of our PCs have dual monitors, I took care to ensure that the screensaver ran on both displays.
This works fine, however on some systems, where the primary screen has been swapped (to the left monitor), the screensaver only works on the left (primary) screen.
The offending code is below. Can anyone see anything I've done wrong, or a better way of handling this?
For info, the context of "this", is the screensaver form itself.
// Make form full screen and on top of all other forms
int minY = 0;
int maxY = 0;
int maxX = 0;
int minX = 0;
foreach (Screen screen in Screen.AllScreens)
{
// Find the bounds of all screens attached to the system
if (screen.Bounds.Left < minX)
minX = screen.Bounds.Left;
if (screen.Bounds.Width > maxX)
maxX = screen.Bounds.Width;
if (screen.Bounds.Bottom < minY)
minY = screen.Bounds.Bottom;
if (screen.Bounds.Height > maxY)
maxY = screen.Bounds.Height;
}
// Set the location and size of the form, so that it
// fills the bounds of all screens attached to the system
Location = new Point(minX, minY);
Height = maxY - minY;
Width = maxX - minX;
Cursor.Hide();
TopMost = true;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要检查 screen.Bounds.Right 而不是 screen.Bounds.Width。
对于身高也是如此。
You want to check
screen.Bounds.Right
rather thanscreen.Bounds.Width
.Similarly for height.