views:

178

answers:

2

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;
+2  A: 

You want to check screen.Bounds.Right rather than screen.Bounds.Width.

Similarly for height.

Anon.
D'oh! Thank you. :)
Bryan
A: 

Changing Width to Right seems to work great for the problem you explained but what about if monitors are stacked? I tried changing Height to Top but this seems to break things. Did you come up with a solution for monitors on top of each other?

Danny