Detect when there is rotation of Windows tablet screen

Asked

Viewed 41 times

1

How do I identify when there was a rotation of the Windows tablet screen?

1 answer

5


According to the documentation (unfortunately only in English) here:

using System.Windows.Forms;
//. . .
//Set event handler
private void Form1_Load(object sender, System.EventArgs e)
{
    int theScreenRectHeight = Screen.PrimaryScreen.Bounds.Height;
    int theScreenRectWidth = Screen.PrimaryScreen.Bounds.Width;
    //Compare height and width of screen and act accordingly.
    if (theScreenRectHeight > theScreenRectWidth)
    {
        // Run the application in portrait, as in:
    MessageBox.Text = "Run in portrait.";
    }
    else
    {
        // Run the application in landscape, as in:
        MessageBox.Text = "Run in landscape.";
    }
}

This method detects whether it is in Landscape or Portrait.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.