• 0

[VB.NET] Display Monitor Identity


Question

Hey gang,

I am looking for the api that is used (if there is one) when the user has multiple monitors and presses the "Identify" button on the Display dialog, Settings tab. (see attached image) I'm writing a an app that can take advantage of multiple monitors and I want to be able to show the user which one is which.

Thanks,

James

post-45653-1264195925305_thumb.jpg

  • Like 1
Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

.NET has a class called Screen (in the System.Windows.Forms namespace), which represents the screens available. However, it does not have an ID associated with it, instead it just provides a device name. In order to get this in .NET, you'll have to make use of the Windows API.

I believe the DISPLAY_DEVICE structure provides what you're looking for: http://msdn.microsoft.com/en-us/library/dd183569%28VS.85%29.aspx

You can iterate through the display devices, using the EnumDisplayDevices function: http://msdn.microsoft.com/en-us/library/dd162609%28VS.85%29.aspx

(There are relevant links on both of those pages, which should give enough information to provide you with what you need to make the necessary native calls)

In addition, here is a page that gives some C# code for using EnumDisplayDevices: http://www.pinvoke.net/default.aspx/user32/EnumDisplayDevices.html

Edited by naaward
Link to comment
Share on other sites

  • 0

Thanks guys,

I already knew about the Screens and AllScreens objects, and the enumDisplays basically does the same thing. What I was hoping for was a way to call that same function that the highlighted button calls. It actually shows a "1", "2", etc on each screen. I can get the height,width,left of each screen and display a number using a transparent form... I was just hoping to use the existing function that Windows uses. (if it's public)

Thanks,

James

Link to comment
Share on other sites

  • 0
On 2/16/2016 at 6:03 AM, Nelson Rodrigues said:

hope ;)

 

Just have tried Win API, windows register, ... Nothing work consistently

Get the array of screens from System.Windows.Forms.Screen.AllScreens and enumerate it. The one that returns true for "Primary" is #1.

 

The DeviceName property will give you a device path that should identify the ID Windows assigned it. (e.g.: "\\\\.\\DISPLAY1")

 

This is buggy on Windows XP and returns garbage in the name so you will have to parse it somehow if you're trying to support that OS.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.