pop & drop forms across multiple monitors

Everything you need is in the Screen class. It will give you references to Screen objects representing the monitors attached to the system and it will give you a Rectangle object that represents the bounds of a Screen. To send a form to a particular monitor you simply set its Location property such that it falls within that Rectangle.
 
Here's a short copy-paste for your pleasure, just add a Listbox to form and try it out.
VB.NET:
Expand Collapse Copy
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
        For Each sc As Screen In System.Windows.Forms.Screen.AllScreens
            ListBox1.Items.Add(sc.DeviceName)
        Next
        Me.Text = "Primary screen is: " & System.Windows.Forms.Screen.PrimaryScreen.DeviceName
    End Sub
 
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles ListBox1.SelectedIndexChanged
        For Each sc As Screen In System.Windows.Forms.Screen.AllScreens
            If sc.DeviceName = ListBox1.Items(ListBox1.SelectedIndex) Then
                Me.Location = sc.WorkingArea.Location
            End If
        Next
    End Sub
 
Ultrawhack, please don't take what I'm about to say the wrong way. You are welcome to post questions here as that is what the forum is for. But some moderators here prefer you to try yourself a bit. :)

That being said, jmcilhinney told you about the Screen class. If you were to look at the Screen class's properties, the very first property is AllScreens which is an array of all displays on the system.

To get a list of a class' methods and properties you can use the object browser in VS (accessed by pressing F2) or through MSDN.com.

Hope that helps.
 
I hear you Paszt. And JohnH, thanks for that code.

Soon I will become familiar with the innards of VS2005E as you guys are and will know all about classes and be able to help others on this very forum with my vast knowledge. Till then, thanks for your patience !
 
JohnH,

the code works great with normal windowstate but will not move the form if the form is maximized. Is this the best workaround ? Thanks. See Paszt, I am trying things myself.

VB.NET:
Expand Collapse Copy
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
        For Each sc As Screen In System.Windows.Forms.Screen.AllScreens
            ListBox1.Items.Add(sc.DeviceName)
        Next
        Me.Text = "Primary screen is: " & System.Windows.Forms.Screen.PrimaryScreen.DeviceName
    End Sub
 
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles ListBox1.SelectedIndexChanged
        For Each sc As Screen In System.Windows.Forms.Screen.AllScreens
            If sc.DeviceName = ListBox1.Items(ListBox1.SelectedIndex) Then
 
[B]Me[SIZE=2].WindowState = FormWindowState.Normal[/SIZE][/B]
 
                Me.Location = sc.WorkingArea.Location
            End If
        Next
    End Sub

 
Last edited:
Back
Top