Search code examples
c#multiple-monitors

C# Check orientation of second screen


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!


Solution

  • 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;
    }