Multiple screens.
-
Wednesday, January 23, 2013 2:02 AM
So i am making a screensaver for a friend of mine and i works except for that it will only work on one monitor. so what i want to do is open my form on each monitor how would i go about doing this.
any help is appreciated, thanks.
All Replies
-
Wednesday, January 23, 2013 2:26 AM
If you're using Windows Forms (ie: the "form"), you can use Screen.AllScreens (http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.allscreens.aspx) to determine the current monitors. You can then open a form with a position based on the Screen.Bounds (http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.bounds.aspx) as needed.
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful". -
Wednesday, January 23, 2013 3:17 AMI see, but how would i open my form on each of the screens.
-
Wednesday, January 23, 2013 4:06 AM
You apparently can only open the form on one screen but you can apparently show your screensaver on multiple screens.
http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/0cd1b342-124a-4ee1-9b14-b56c9d8fc7a9
"Use system.WIndows.Forms.Screen.AllScreens to return an array of all displays on the system...and then show your screen saver on each display."
You've taught me everything I know but not everything you know.
-
Wednesday, January 23, 2013 3:13 PM
my new code to add the the screen saver is,
For Each scr As Screen In System.Windows.Forms.Screen.AllScreens
Dim frm As New screensaverDim bou As Rectangle = scr.Bounds
Dim t As Integer = bou.Top
Dim w As Integer = bou.Left
frm.Location = New System.Drawing.Point(t, w)
frm.Show()
Next scr
but after adding this code my app crashes the computer what did i do wrong.
-
Wednesday, January 23, 2013 5:00 PM
my new code to add the the screen saver is,
For Each scr As Screen In System.Windows.Forms.Screen.AllScreens
Dim frm As New screensaverDim bou As Rectangle = scr.Bounds
Dim t As Integer = bou.Top
Dim w As Integer = bou.Left
frm.Location = New System.Drawing.Point(t, w)
frm.Show()
Next scr
but after adding this code my app crashes the computer what did i do wrong.
What is the exception you're receiving? That will tell us what's wrong...
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful". -
Wednesday, January 23, 2013 9:00 PMI am not getting an error, it is just not exciting my code. freezing up the computer and then crashing a few minutes later.
-
Wednesday, January 23, 2013 9:06 PM
Can you show your original code vs. the new code? Are you calling Application.Run()?
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful". -
Wednesday, January 23, 2013 9:48 PM
"but after adding this code my app crashes the computer what did i do wrong."
I doubt it's the reason for the crash, but have you taken into consideration that the screen resolutions could be different for each monitor?
--
Andrew -
Wednesday, January 23, 2013 10:30 PM
I have, my form is set to a default size of 1024, 768 and the form's window stare is set to maximized.
and the code in the before and after is,
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
tim.Interval = 1
tim.Enabled = True
Cursor.Hide()
End Sub and afterPrivate Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
tim.Interval = 1
tim.Enabled = True
Cursor.Hide()
For Each scr As Screen In System.Windows.Forms.Screen.AllScreens
Dim frm As New form2
Dim bou As Rectangle = scr.Bounds
Dim t As Integer = bou.Top
Dim w As Integer = bou.Left
frm.Location = New System.Drawing.Point(t, w)
frm.Show()
Next scr
End Subso i hope that helps you see my predicament.
-
Wednesday, January 23, 2013 11:52 PM
Is this all in "form2"?
If so, you're recursively creating forms, which will just eat up CPU and memory until you run out of memory or stack space and crash.
Instead, you probably need to put this logic into your Program.cs file... You can show the forms, then call Application.Run() once.
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful". -
Wednesday, January 23, 2013 11:58 PM
yes this is all in form2.
but no i am only creating this form twice with 2 monitors, i think. if i am wrong and i have some stupid somthing in my code please let me know.
otherwise, what do you mean by "you probably need to put this logic into your Program.cs file..."
-
Thursday, January 24, 2013 12:01 AM
When you load the form (form1_Load), it creates 1 Form2 instance per monitor - these then load, and each of them creates 1 form2 per monitor, then these load, and create 1 per monitor, etc...
You're starting with 1, but then they recursively create and show more :)
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".- Marked As Answer by BenDoyle Thursday, January 24, 2013 2:27 AM
-
Thursday, January 24, 2013 2:27 AMthanks for all the help.

