Results 1 to 6 of 6

Thread: Screen Position

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Location
    United States
    Posts
    29

    Screen Position

    Hey

    I'm working with a multi monitor setup. I know that you can do Screen.AllScreens(x) to get a specific screen, but is there any way to identify which screen is in which position?

    I.E.

    Screen 0 is on the right, screen 1 is on the left, screen 2 is in the middle

    I'm trying to position one form at the top left of each screen, and the only way i can think to do this is something like

    Code:
    Me.Location = New Point(-Screen.AllScreens(1).Bounds.Width, Screen.AllScreens(1).Bounds.Top)
    (That is assuming that screen 1 is on the left)

    Any help?
    If I fail... You can prolly go anywhere else and get teh right answer

    Please Visit my site:
    http://www.fiscalleti.com/

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Screen Position

    There's no way to determine where the monitors are physically but almost everyone with multiple monitors will match their logical layout to their physical layout and you can determine logical layout. You can get the Top and Left from the Bounds of each Screen and then compare them. Using the Left, lower numbers are on the left and higher numbers are on the right. using the Top, lower numbers are above and higher numbers are below. With a bit of maths, you can determine the relative layout of all monitors.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Location
    United States
    Posts
    29

    Re: Screen Position

    The only real problem I see with this is that Point(0, 0) relates to Monitor 0. So, To get 0,0 on the left monitor you have to do -Left Monitor Width...
    If I fail... You can prolly go anywhere else and get teh right answer

    Please Visit my site:
    http://www.fiscalleti.com/

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Screen Position

    Quote Originally Posted by thefiscster View Post
    The only real problem I see with this is that Point(0, 0) relates to Monitor 0. So, To get 0,0 on the left monitor you have to do -Left Monitor Width...
    I think I understand correctly what you're saying but, if I do, then you're wrong. Here's some code that I just tested on my own four-monitor setup at work and it puts a form in the top, left corner of each monitor in order from left to right:
    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    4.         Dim number = 1
    5.  
    6.         For Each scr In Screen.AllScreens.OrderBy(Function(s) s.Bounds.Left)
    7.             Dim f As New Form With {.Text = number.ToString(),
    8.                                     .StartPosition = FormStartPosition.Manual,
    9.                                     .Location = scr.Bounds.Location}
    10.  
    11.             f.Show()
    12.  
    13.             number += 1
    14.         Next
    15.     End Sub
    16.  
    17. End Class
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Screen Position

    jmcilhinney's code works ok with my 4 screen setup too.

    try this:

    Code:
    Dim screens() As Screen = Screen.AllScreens
    Dim order As New List(Of Screen)
    order.Add(screens.First(Function(s) s.Bounds.Right = screens.Max(Function(sr) sr.Bounds.Right))) ' 0 = rightmost
    order.Add(screens.First(Function(s) s.Bounds.Left = screens.Min(Function(sr) sr.Bounds.Left))) ' 1 = leftmost
    order.Add(screens.Except(order).First) ' 2 = middle

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Location
    United States
    Posts
    29

    Re: Screen Position

    Quote Originally Posted by jmcilhinney View Post
    I think I understand correctly what you're saying but, if I do, then you're wrong. Here's some code that I just tested on my own four-monitor setup at work and it puts a form in the top, left corner of each monitor in order from left to right:
    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    4.         Dim number = 1
    5.  
    6.         For Each scr In Screen.AllScreens.OrderBy(Function(s) s.Bounds.Left)
    7.             Dim f As New Form With {.Text = number.ToString(),
    8.                                     .StartPosition = FormStartPosition.Manual,
    9.                                     .Location = scr.Bounds.Location}
    10.  
    11.             f.Show()
    12.  
    13.             number += 1
    14.         Next
    15.     End Sub
    16.  
    17. End Class
    Thank you so much! I for whatever reason didn't think to order it by the Left values. Works perfect, Thanks again
    If I fail... You can prolly go anywhere else and get teh right answer

    Please Visit my site:
    http://www.fiscalleti.com/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width