4

I have written a code which rotates my 3rd display.

Now I want to check first, in which orientation the display currently is.

I wrote the following code:

    int scrRectHeight = Screen.PrimaryScreen.Bounds.Height;
    int scrRectWidth = Screen.PrimaryScreen.Bounds.Width;

    if (scrRectHeight > scrRectWidth)
    {
        Display.Rotate(3, Display.Orientations.DEGREES_CW_90;
    }
    else
    {
        Display.Rotate(3, Display.Orientations.DEGREES_CW_180;
    }

This works fine, but it only works for the primary display. I can't find a definition to change it to a second display. How can I change it, or is there another method? Thanks!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tim
  • 143
  • 9
  • Consider to not use PrimaryScreen if you meant to look at the properties of the second screen, Screen.AllScreens[1]. – Hans Passant Dec 01 '18 at 14:00
  • @HansPassant I didn't understand how to use AllScreens. It's so simple! Thanks – Tim Dec 01 '18 at 14:09
  • @HansPassant Could you add it as an answer so I can mark it? – Tim Dec 01 '18 at 14:11
  • I have a hard time identifying the brain-bug in this code. Just share what you discovered in your own post and mark it as the answer. – Hans Passant Dec 01 '18 at 14:16
  • [Using SetWindowPos with multiple monitors](https://stackoverflow.com/questions/53012896/c-sharp-user32-using-setwindowpos-with-multiple-monitors?answertab=active#tab-top) – Jimi Dec 01 '18 at 19:03

1 Answers1

2

There is not "SecondaryScreen" property.

Try this instead:

int secondRectHeight = Screen.AllScreens[1].Bounds.Height;
int secondRectWidth = Screen.AllScreens[1].Bounds.Width;

if (secondRectHeight > secondRectWidth)
{
    Display.Rotate(3, Display.Orientations.DEGREES_CW_90;
}
else
{
    Display.Rotate(3, Display.Orientations.DEGREES_CW_180;
}