There are many facets of "orientation-aware" apps. There are 2 portrait and 2 landscape modes making 4 possible orientations (0, 90, 180, 270).
I have an application that lets the user set custom keys in an application. At first, I thought I only need to store a landscape set and a portrait set; however, depending on the user, the landscape mode might be in the 90 degree position or the 270 degree position. The keys selected by the user may be very different depending on which one of these orientations gets used.
However, it is very simple to find out what the current screen orientation in on the device:
Imports Microsoft.WindowsCE.Forms
.
.
.
Select Case SystemSettings.ScreenOrientation
Case ScreenOrientation.Angle0
.
.
.
Case ScreenOrientation.Angle90
.
.
.
Case ScreenOrientation.Angle180
.
.
.
Case ScreenOrientation.Angle270
.
.
.
End Select
More Info at:
http://msdn2.microsoft.com/en-us/library/microsoft.windowsce.forms.systemsettings.screenorientation(VS.80).aspx
This blog is a depository for things I have found regarding VB.NET and C#.NET development (and other things I may need to remember). This blog is primarily for my own reference, but if the information I found is useful to others, then that is great. If others want to contribute with comments or other information, then that is great too.
Thursday, January 3, 2008
Detecting Screen Orientation Changes in Windows Mobile Apps
If you are working on a Windows Mobile application, you probably need to be orientation-aware. If the user changes the screen from portrait to landscape or vice versa, you may need to do something based on this change.
The Resize event for the form will tell you when an orientation change has occured. You will probably have to use the me.Width and me.Height to know how it was changed. Look at the If statement in the UpdateButtonLayout sub below.
Private Sub Form_NumberEntry_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
UpdateButtonLayout()
End Sub
Private Sub UpdateButtonLayout()
Dim ratio As Double = CInt(Me.Width) / CDbl(Me.Height)
If ratio <= 0.9 Then ' portrait .
.
.
Else ' landscape
.
.
.
End If
End Sub
Being orientation away for control may be as simple as using the Anchor and Dock properties on the control, but there are many times, that this is not sufficient or that you need to do something else like auto fit columns in a listview.
The Resize event for the form will tell you when an orientation change has occured. You will probably have to use the me.Width and me.Height to know how it was changed. Look at the If statement in the UpdateButtonLayout sub below.
Private Sub Form_NumberEntry_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
UpdateButtonLayout()
End Sub
Private Sub UpdateButtonLayout()
Dim ratio As Double = CInt(Me.Width) / CDbl(Me.Height)
If ratio <= 0.9 Then ' portrait .
.
.
Else ' landscape
.
.
.
End If
End Sub
Being orientation away for control may be as simple as using the Anchor and Dock properties on the control, but there are many times, that this is not sufficient or that you need to do something else like auto fit columns in a listview.
Subscribe to:
Posts (Atom)