Velutis
Velutis

Reputation: 103

How to get screen identification number from Screen class

i need to show dialog in screen by its identification number, for example i have this situation screen setup on windows

I want to show something on fourth, when i get all screens by using Screen.AllScreens, my fourth screen is 0 element in array, because AllScreens returns screens not by indent number but by squence. So mayby someone knows the way how to get identification number from Screen class, or how to get screen coordinates and bounds by its identification number.

UPDATE:

DeviceName is not always corrspont to identification number (see image below):

enter image description here

Upvotes: 6

Views: 2647

Answers (2)

001
001

Reputation: 13533

If you look at screen.DeviceName you should get \\\\.\\DISPLAY1, \\\\.\\DISPLAY2, etc. You can use this to search for \\\\.\\DISPLAY4.

Upvotes: 1

Dmitriy.Nemykin
Dmitriy.Nemykin

Reputation: 240

To get screen number (dirty way, but it works):

 var sceenId = -1;
 var targetScreen = Screen.FromPoint(Cursor.Position);
 for (var i = 0; i < Screen.AllScreens.Length; i++)
 {
     if (!Equals(targetScreen, Screen.AllScreens[i]))
         continue;
     sceenId = i;
     break;
 }

To get screen coordinates and bounds by its identification number:

Screen.AllScreens[sceenId].Bounds

Upvotes: 0

Related Questions