Question Working with Dual Monitors - Need to determine Display Number

tp5harp

New member
Joined
May 12, 2012
Messages
4
Programming Experience
3-5
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.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,372
Location
Sydney, Australia
Programming Experience
10+

tp5harp

New member
Joined
May 12, 2012
Messages
4
Programming Experience
3-5
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.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,372
Location
Sydney, Australia
Programming Experience
10+
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.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,461
Location
Norway
Programming Experience
10+
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)
 

tp5harp

New member
Joined
May 12, 2012
Messages
4
Programming Experience
3-5
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.
 
Top Bottom