Results 1 to 9 of 9

Thread: Working with Dual Monitors - Need to determine Display Number

  1. #1
    tp5harp is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2012
    Posts
    4
    Reputation
    0

    Working with Dual Monitors - Need to determine Display Number

    Hi All,

    I have been looking at the Screen class in vb.net, as I want users to be able to define which screen a particular form is displayed on. I have worked out how to do this, however there is a small problem.

    If in Windows I go to the standard Display Settings I can see one of my monitors showing as number 1 and the other as number 2.

    Screens.png

    However in the vb.net code the I cannot determine which one is which. If I use the DeviceName property it returns "\\.\DISPLAY1" and "\\.\DISPLAY2", however this is the opposite way round to the numbers shown in the Windows Display Settings.

    When I give users the choice as to which screen to show the form on, if they choose screen 1, I need to make it screen 1 as per the Windows Display settings, not Display1 as defined in the Screen class.

    Can anyone advise me of how to find this information so that I can display the form on the correct screen.

    Many thanks,

    Trevor.

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,364
    Reputation
    1544
    If you loop through Screen.AllScreens, does the order of the elements match what you see in the Windows Display dialogue?

  3. #3
    tp5harp is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2012
    Posts
    4
    Reputation
    0
    Quote Originally Posted by jmcilhinney View Post
    If you loop through Screen.AllScreens, does the order of the elements match what you see in the Windows Display dialogue?
    Sadly not, it ordered them by the screen index which was in the reverse order.

  4. #4
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,209
    Reputation
    2369

  5. #5
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,364
    Reputation
    1544
    Quote Originally Posted by JohnH View Post
    '1' is the primary screen: Screen Properties (System.Windows.Forms)
    That is a point of distinction for two monitors so if you only have to worry about two then that is a good idea. I have four at work though, so that would not be of use if you have to distinguish an arbitrary number of monitors.

  6. #6
    tp5harp is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2012
    Posts
    4
    Reputation
    0
    That is what concerns me, John's solution would work probably in the majority of cases, but ideally I would like to cater for all possible configurations.

  7. #7
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,364
    Reputation
    1544
    I just had a quick investigate and the AllScreens property internally calls the EnumDisplayMonitors API. If that doesn't do what you want already then the only option that I can think of likely to do what you want would be WMI.

  8. #8
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,209
    Reputation
    2369
    AllScreens is ordered by location for me, but if that is not the case you could try that too:
    Dim ordered = Screen.AllScreens.OrderBy(Function(sc) sc.Bounds.Left)

  9. #9
    tp5harp is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    May 2012
    Posts
    4
    Reputation
    0
    The problem with mine is it is returning the left most screen as display 1, despite my configuration having the screen to the right as screen 1. I think WMI may be the way to go. Just a seems a lot more complicated to me that the managed code.

    Thanks all for your help.

    Trevor.

Tags for this Thread

Bookmarks

Posting Permissions

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