5

How to have a function in C# to run the window identification, which will show the numbers 1, 2, ... on the screen same way as we do it by right click on the screen (properties) then we go to Screen Resolution and show the numbers by clicking on Identify.

Can we do that in C#?

Timwi
  • 65,159
  • 33
  • 165
  • 230
Data-Base
  • 8,418
  • 36
  • 74
  • 98

3 Answers3

7

Yes, look at the Screen class: http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.aspx

You can get a list of all screens through Screen.AllScreens.

Lloyd
  • 29,197
  • 4
  • 84
  • 98
  • Thank you, I know this part, but I mean how to make my system Show a big white numbers in the middle of the screens using c#! you know what I mean? – Data-Base Sep 27 '10 at 14:21
  • Then you need to do a search for drawing on the desktop, quite a common question, check out this for example - http://stackoverflow.com/questions/1536141/how-to-draw-directly-on-the-windows-desktop-c – Lloyd Sep 27 '10 at 22:38
1
foreach(var screen in System.Windows.Forms.Screen.AllScreens)
{
   string display_number = Regex.Match(screen.DeviceName,@"\d+").Value;
   Console.WriteLine($"Display Number = {display_number} isPrimary= {screen.Primary}");
}

Output:

Display Number = 1 isPrimary= False
Display Number = 2 isPrimary= True
Display Number = 3 isPrimary= False
Elshan
  • 7,339
  • 4
  • 71
  • 106
  • This should be marked as the answer. It was the only answer that addressed the OP's question of getting the Windows display number (open Display Settings and click Identify button), rather than just getting the list of displays from the OS. This answer's addition of using RegEx to decode the display name string was the most helpful in converting the AllScreens list to matching OS display numbers. – Richard May 11 '23 at 15:22
0

Using the Screen.AllScreens Property does get an array of the monitors attached to the system.

Then Screen.DeviceName Property will give you it's name. However, that might not be the same as the number as the MSDN warns:

This string may contain non-printable characters.

I'd check this first to see if this gives you what you need.

ChrisF
  • 134,786
  • 31
  • 255
  • 325