Programmatically Rotating the Screen using the .NET Compact Framework
Several months back, I wrote about how to
determine whether or not a device supported screen rotation. This post prompted the question of how to programmatically rotate the device..
The snippets below check the device's current display orientation. If portrait (Angle0), the orientation is changed to landscape (Angle90). If the device has any orientation other than Angle0, it is changed to portrait.
C#//---------------------------------------------------------------------
//THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//PARTICULAR PURPOSE.
//---------------------------------------------------------------------
using System;
using Microsoft.WindowsCE.Forms;
class Program
{
static void Main()
{
if(SystemSettings.ScreenOrientation == ScreenOrientation.Angle0)
{
// if portrait, change to landscape
SystemSettings.ScreenOrientation = ScreenOrientation.Angle90;
}
else
{
// change to portrait
SystemSettings.ScreenOrientation = ScreenOrientation.Angle0;
}
}
}VB'---------------------------------------------------------------------
'THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
'KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
'IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'PARTICULAR PURPOSE.
'---------------------------------------------------------------------
Imports Microsoft.WindowsCE.Forms
Module Module1
Sub Main()
If (SystemSettings.ScreenOrientation = ScreenOrientation.Angle0) Then
' if portrait, change to landscape
SystemSettings.ScreenOrientation = ScreenOrientation.Angle90
Else
' change to portrait
SystemSettings.ScreenOrientation = ScreenOrientation.Angle0
End If
End Sub
End ModuleFor more information on this and other cool settings provided by the
Microsoft.WindowsCE.Forms namespace, check out the MSDN documentation for
SystemSettings.
Enjoy!
--DK
Disclaimer(s):
This posting is provided "AS IS" with no warranties, and confers no rights.