简体   繁体   中英

How do I get the same screen arrangement that windows Display has in C#?

I'm trying the following code:

foreach (var screen in Screen.AllScreens)
{
    // For each screen, add the screen properties to a list box.
    Console.WriteLine("Device Name: " + screen.DeviceName);
    Console.WriteLine("Bounds: " + screen.Bounds.ToString());
    Console.WriteLine("Working Area: " + screen.WorkingArea.ToString());
    Console.WriteLine("Primary Screen: " + screen.Primary.ToString());
    Console.WriteLine("=====================================================");
}

And I get this:

Device Name: \\.\DISPLAY1
Bounds: {X=3840,Y=0,Width=3840,Height=2160}
Working Area: {X=3840,Y=0,Width=3840,Height=2120}
Primary Screen: False
=====================================================
Device Name: \\.\DISPLAY2
Bounds: {X=-3840,Y=0,Width=3840,Height=2160}
Working Area: {X=-3840,Y=0,Width=3840,Height=2120}
Primary Screen: False
=====================================================
Device Name: \\.\DISPLAY3
Bounds: {X=0,Y=0,Width=3840,Height=2160}
Working Area: {X=0,Y=0,Width=3840,Height=2120}
Primary Screen: True
=====================================================

Which is cool, but the values don't seem to match. This is my current arrangement. Notice that Display 2 is the primary monitor. However, the C# code shows Display 3 as primary, which is wrong.

在此处输入图像描述

I assume there must be a bug in the Screen class (using .NET 4.8, Windows 10), so what is a better way to get the screen position, bounds, arrangement and primary/secondary just like the Display panel does?

Any ideas welcome, thanks!

WorkingArea X and Y give you the monitor coordinates and then with a little two-dimensional cartesian plane calculation you can figure monitor positions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM