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.
 
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.
 
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.
 
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)
 
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.
 
Back
Top