C# Identfiy screens number?
Asked Answered
D

3

6

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#?

Direful answered 23/9, 2010 at 8:56 Comment(0)
S
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.

Spy answered 23/9, 2010 at 8:58 Comment(2)
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?Direful
Then you need to do a search for drawing on the desktop, quite a common question, check out this for example - #1536641Spy
A
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
Aeneid answered 21/6, 2021 at 12:6 Comment(1)
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.Inmost
T
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.

Trichocyst answered 18/3, 2011 at 10:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.