C# Multiple Monitor Problem

Building a Screen Saver to use multiple monitors for one large area.

Page 1 of 1

3 Replies - 4616 Views - Last Post: 23 January 2010 - 11:27 AM Rate Topic: -----

#1 Notorion  Icon User is offline

  • D.I.C Regular

Reputation: 35
  • View blog
  • Posts: 378
  • Joined: 17-February 09

C# Multiple Monitor Problem

Posted 21 January 2010 - 03:59 PM

Hello,

I have built a screen saver which has the white background, and then the image. The image is set to move to a random location (within screen bounds) once every 10 seconds, and the application closes if an event gets sent to it by windows.


Basically I tried first using this.Screen.Bounds for X and Y and then moved the image in between those bounds (less the size of the image of course).


Essentially, my question to DIC users and admins is how would I span together multiple monitors (# of monitors varies from computer to computer) to create one large area that I can fill with my background image (solid white) and move the image within all of the screens. Also, to further illustrate my project, If the image were to happen to land in the dead middle of say 2 monitors the image should split half on the first monitor and half on the second.


Now, I have tried to implement this on some level, but it isn't correctly spanning to multiple monitors. If you would like to see my code for what I have done, I can surely provide it (for proof that I really am doing this), but I was hoping to get further ideas on how to do this. Also, I have been looking into Screen.Allscreens. If you have any suggestions I would like to hear them.

This post has been edited by Notorion: 21 January 2010 - 04:01 PM


Is This A Good Question/Topic? 0
  • +

Replies To: C# Multiple Monitor Problem

#2 ragingben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 170
  • View blog
  • Posts: 637
  • Joined: 07-October 08

Re: C# Multiple Monitor Problem

Posted 22 January 2010 - 02:35 AM

Interesting problem. You were defiently correct in suggesting Screen.AllScreens, which is an array of screens. Using this you can get the width of all the screens by examining each Screen object...
	// get all screens
	Screen[] monitors = Screen.AllScreens;

	// hold total width
	Double totalWidth = 0;

	// itterate screens
	foreach (Screen screen in monitors)
	{
		// display some debug info
		Console.WriteLine("Screen {0} {1} the primary screen and has a width of {2}", screen.DeviceName, screen.Primary ? "is" : "is not", screen.WorkingArea.Width);

		// increase total width
		totalWidth += screen.WorkingArea.Width;
	}

	// display total width
	Console.WriteLine("All screens combined width is {0}", totalWidth);


... and with that total width you could create a form the same width, which would stretch over the entire display and windows will handle the rest - i.e splitting the image over two monitors.
Was This Post Helpful? 1
  • +
  • -

#3 Crehl  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 49
  • Joined: 25-January 09

Re: C# Multiple Monitor Problem

Posted 22 January 2010 - 11:03 AM

Be careful, ragingben - that code assumes all the monitors are in a line, side-by-side. If they're on top of each other, strange things might happen ;)

Recording the minimum X value, and the maximum (X+Width) for all the screens may be a solution in cases where monitors are stacked on top of each other. The width is then calculated after looping through all the screens. I know Windows 7 (If not others) allows for this functionality out of the box, but I'm not sure how this is represented within .NET

Of course, if the OP knows the monitors will always be side-by-side, everything I've just said can be disregarded, though possibly not without consequences in the future if circumstances change, or the code is reused in another situation.
Was This Post Helpful? 0
  • +
  • -

#4 ragingben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 170
  • View blog
  • Posts: 637
  • Joined: 07-October 08

Re: C# Multiple Monitor Problem

Posted 23 January 2010 - 11:27 AM

Fair point Crehl - I'm so used to having monitors side by side that I didn't even consider that they wouldn't be!

This post has been edited by ragingben: 23 January 2010 - 11:31 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1