How to determine screen orientation in C # for mobile devices?

How can I find out in C # -Application in which direction the screen of a mobile device is oriented? (i.e. horizontal or vertical).

+4
source share
4 answers

Microsoft.WindowsMobile.Status has a class that tracks all kinds of properties of your device. In addition to what you need, DisplayRotation, it also contains phone coverage properties, Nr missed calls, the next destination, and more. See msdn for more information.

You can also add an event handler to notify you of changes to these properties.

+3
source

Add a link to Microsoft.WindowsCE.Forms in your project. You can then reference Microsoft.WindowsCE.Forms. A SystemSettings.ScreenOrientation property that will give you what you need.

By the way, you can set this property, so it can also be used to set the screen orientation.

+2
source

You must add 2 project disclaimer: Microsoft.WindowsMobile Microsoft.WindowsMobile.Status

then you can use this code to determine the orientation:

int orientation=Microsoft.WindowsMobile.Status.SystemState.DisplayRotation; if(orientation== 90 || orientation==-90 || orientation==270) //Landscape is 90 or -90 or 270 { //your code; } else { //your code; } 
+1
source

Just guess, but my first attempt:

 var rect = System.Windows.Forms.Screen.PrimaryScreen.Bounds; // or var rect = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea; var ratio = rect.Width / rect.Height; if (ratio == 1.0) // square screen. if (ratio > 1.0) // landscape. if (ratio < 1.0) // portrait. 
0
source

All Articles