|
How do you code a screen saver in C# or VB.net (preferably express editions) to display on dual monitors?
Thanks
[I looked at this article: http://www.geekpedia.com/tutorial65_How-to-make-a-screen-saver.html, but it did not accuratley display the screensaver on both monitors.]
| | Epoh Rio Tuesday, May 27, 2008 5:30 PM | Okay, I looked at that sample code that you downloaded.
Here are the changes you need:
At the bottom of the scrClass.cs file, in that else block, change everything in there to the following:
Code Snippet
new Form1(0).ShowDialog();
In the Form1_Load void in Form1.cs, change the part under"// Set the bounds of the form..." to the following:
Code Snippet
this .Bounds = new Rectangle(new Point(0,0), new Size(Screen.AllScreens[1].Bounds.Right, Screen.AllScreens[1].Bounds.Bottom));
That should be it.
IMPORTANT: This is just to get it to work and point you in the right direction. These changes, as they are, will not work on a machine with only one display or more than two, and won't be right if the second display is not the same size, resolution,or orientation as the first (on my machine, for example, I have the left monitor in portrait and the right in landscape).
You have to iterate through the Screen.AllScreens array and dynamically set this.Bounds to cover the total display area.
You can also get rid of all the stuff about passing an int when the form is created, as this is the part that causes the screensaver to display on only one screen at a time. | | JayStation3 Friday, May 30, 2008 1:25 AM | I believe that the way in which dualhead displays show screensavers is based on display settings custom to the video hardware.
Most vendors provide an interface application that allow the user to select how they want to use the two (or more) displays (duplicate displays, spanning, virtual separate desktops, etc.), and those settings typically include what to do with screensavers.
Assuming that this in fact the case, I don't think that you have to do any special coding to handle multiple displays.
Try running a Windows built-in screensaver and see if the behaviour is different than what you're getting with your own creation. | | JayStation3 Tuesday, May 27, 2008 8:54 PM | I tried, some of the built in screen savers. (Windows XP)
The Windows XP screen saver works on both screens, mine displays on the first screen but not on the second until I move the mouse/press a key, then it requires an additional bump of the mouse or another key down at that point it moves to the second screen. I have tested the screen saver on single monitor PCs and it works great.
It just doesnt work on dual monitor PCs.
Thanks
| | Epoh Rio Wednesday, May 28, 2008 1:53 PM |
Do you see "two" screen savers running independently (a screen saver on each screen), or one screen saver that crosses the boundary between displays?
The code provided from the link you referenced does provide for multiple displays. Did you end up using C# sample code provided there, or did you go from scratch? If the latter, did you include the bit that refers to Screen.AllScreens? | | JayStation3 Wednesday, May 28, 2008 5:55 PM | The dual screens were not running independently or in sync.
The screen saver started on the primary screen (did not display on the second screen) until mouse/key down, then it would switch to the second screen until mouse/key down.
I did use the C# sample provided.
I am not the only person to apparently have problems with this. I read where other posters were getting the same issue. There were a couple of “fixes�but neither worked for me.
Thanks, | | Epoh Rio Thursday, May 29, 2008 1:09 PM |
Well there are several issues that could be giving you trouble. One, which multiple display mode are you using? Besides the multiple independent windows mode that the OS provides, graphics card drivers provide other modes as well. These different modes each have their quirks. I'll assume you mean the multiple independent mode from here on.
Next, is your screensaver graphical, using hardware accelerated rendering? There are numerous issues with displaying hardware accelerated graphics on secondary displays.
Are you reading the screen position info at the start of your program? Here is a code snippet (VB) that I use when opening a window to see if the coordinates are within the display area. It isn't exactly what you need, but you should be able to play around and get it to give you the coordinates of each screen.
Code Snippet
Dim a As Integer
Dim NumofDisplays As Integer
' Gets an array of all the screens connected to the system.
Dim TheScreens() As System.Windows.Forms.Screen = System.Windows.Forms.Screen.AllScreens
NumofDisplays = TheScreens.GetUpperBound(0)
Dim EntireBounds As Rectangle
For a = 0 To NumofDisplays
If a = 0 Then
EntireBounds = TheScreens(a).WorkingArea
Else
If TheScreens(a).WorkingArea.X < EntireBounds.X Then
EntireBounds.X = TheScreens(a).WorkingArea.X
End If
If TheScreens(a).WorkingArea.Y < EntireBounds.Y Then
EntireBounds.Y = TheScreens(a).WorkingArea.Y
End If
If TheScreens(a).WorkingArea.X + TheScreens(a).WorkingArea.Width > EntireBounds.X + EntireBounds.Width Then
EntireBounds.Width = TheScreens(a).WorkingArea.X + TheScreens(a).WorkingArea.Width
End If
If TheScreens(a).WorkingArea.Y + TheScreens(a).WorkingArea.Height > EntireBounds.Y + EntireBounds.Height Then
EntireBounds.Height = TheScreens(a).WorkingArea.Y + TheScreens(a).WorkingArea.Height
End If
End If
Nexta
Console.Writeline("Total working display area: " & EntireBounds.ToString)
Until you figure out what the problem is, I would suggest that you create an individual form for each display screen, positioning it using the coordinates from the (modified)routine above. Just set the color to black on all of the secondary displays. Once you get your screensaver working well on the primary screen, you can look at getting it to display on all of the screens.
| | LogLivePlinko Thursday, May 29, 2008 1:37 PM | Yes I am using Windows Display settings to extend the Windows desktop onto the second monitor.
| | Epoh Rio Thursday, May 29, 2008 4:55 PM | Okay, I looked at that sample code that you downloaded.
Here are the changes you need:
At the bottom of the scrClass.cs file, in that else block, change everything in there to the following:
Code Snippet
new Form1(0).ShowDialog();
In the Form1_Load void in Form1.cs, change the part under"// Set the bounds of the form..." to the following:
Code Snippet
this .Bounds = new Rectangle(new Point(0,0), new Size(Screen.AllScreens[1].Bounds.Right, Screen.AllScreens[1].Bounds.Bottom));
That should be it.
IMPORTANT: This is just to get it to work and point you in the right direction. These changes, as they are, will not work on a machine with only one display or more than two, and won't be right if the second display is not the same size, resolution,or orientation as the first (on my machine, for example, I have the left monitor in portrait and the right in landscape).
You have to iterate through the Screen.AllScreens array and dynamically set this.Bounds to cover the total display area.
You can also get rid of all the stuff about passing an int when the form is created, as this is the part that causes the screensaver to display on only one screen at a time. | | JayStation3 Friday, May 30, 2008 1:25 AM | Thanks for that nice code, LogLivePlinko, it helped me troubleshoot my problem and explore the screen properties. | | Unfriendly Fire Wednesday, August 19, 2009 4:47 PM | Hi , I have got this working across both of my screens but without adding the code :
new Form1 (0).ShowDialog();
Mainly because I couldn't workout where to put it, should i be replacing this :
System.Windows.Forms.Application.Run(new Form1(x));
With
System.Windows.Forms.Application.Run(new Form1(0).ShowDialog); | | 3wsparky Tuesday, October 06, 2009 2:57 PM |
|