.NET thinks screens are ordered differently than Windows Control Panel | Display | Screen Resolution does

大兔子大兔子 提交于 2019-12-01 08:33:24

问题


Weird thing I saw last night on a PC running Windows 7 Embedded Standard 64-bit with 2 monitors connected. The Display Resolution dialog shows the monitors as being display 1 and display 2 (from left to right). When I run a program I wrote that used both screens, the output I expected on display 1 showed up on the rightmost display, and the output I expected on display 2 showed up on the leftmost display.

Spent some time here and on Google, and ended up using some code I found to create a console app that displayed the contents of the System.Windows.Forms.Screen.AllScreens:

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

Ran it on one test machine and got what I expected -- AllScreens order matches the DIsplay Resolution dialog order.

But on the problematic machine, the output of the code above came out reversed. DISPLAY1 was at a position that was the second screen (rightmost), and DISPLAY2 was positioned at the leftmost screen.

That's really weird. Since this WASN'T using my program, it's something in the innards of .NET. The same code works on other similar machines, so I don't think it's a general problem, but is a problem isolated to this machine. I've tried more searching for similar problems but have come up empty, probably due to the search terms (monitor, screen, .NET all match a LOT of items that have nothing to do with this issue).

Anyone seen this before, and ideally, have an idea on how to fix it? Reinstalling the .NET 4 package did not help. Changing locations in the Display Resolution dialog and then changing them back did not help, even with a reboot in between.

Thanks.


回答1:


The AllScreens property is populated via the EnumDisplayMonitors function.

The documentation for EnumDisplayMonitors does not indicate what order it returns the monitors in, thus one can infer it is an implementation detail which can change from OS version to OS version.



来源:https://stackoverflow.com/questions/13979118/net-thinks-screens-are-ordered-differently-than-windows-control-panel-display

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!