问题
I have a c# windows application that work with multimonitors. The application has a main form that must be showed in the primary display and a full screen form that needs to be displayed on the second screen (this second form is showed in a 3d goggles).
This is my way to assign the screens:
Screen.AllScreens[0]
for first screen and Screen.AllScreens[1]
for secondary screen but i'm having problems with a new version of the 3d goggles because this are HDMI and even if i set the main screen to the monitor (DVI), the goggles are set as screen 1.
Could be a better way to use Screen.AllScreens[0].Bounds.X == 0
as a way to check if the screen 0 is the primary screen?
Update: I used before Screen.AllScreens[x]
the property Screen.PrimaryScreen
but that property also give me troubles with some monitor-goggles configuration that i really don't remember them.
回答1:
Note that in Windows, it is possible to move the primary/secondary display to any position (I spent several years with my secondary monitor on top of the primary) and thus checking for bounds would be useless.
Instead, note that the Screen
class has a Primary Property to check whether a given screen is primary. You could thus
secondaryScreen = Screen.AllScreens
.Where(s => s.Primary == false)
.Single(); // Note: this will throw an exception if there isn't a secondary screen, or more than one.
... or the PrimaryScreen static Property to get the primary Screen
directly.
来源:https://stackoverflow.com/questions/28506288/get-real-primary-screen-in-c-sharp-with-a-multi-monitor-setup