我编写了一个简单的屏幕保护程序,它已部署到我们公司的所有客户端 PC 上。
由于我们的大多数 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;