2009-12-18 37 views
0

我有一个简单的屏幕保护程序,我已经写入,已部署到我们公司的所有客户端PC。Windows屏幕保护程序多显示器问题

由于我们大多数的个人电脑都配有双显示器,因此我确保屏幕保护程序在两台显示器上均可运行。

这可以正常工作,但是在一些系统上,主屏幕已被交换(到左侧显示器),屏幕保护程序只能在左侧(主要)屏幕上工作。

违规代码如下。任何人都可以看到我做错了什么,或者更好的处理方式?

有关信息,“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; 

回答

3

您要检查screen.Bounds.Right而非screen.Bounds.Width

类似的高度。