Portrait only?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to make one's application *ONLY* work in portrait mode without
to much effort?
 
Whaqt do you mean? Have the app not load if the device is landscape or
something like that? You could always check the screen dimensions at
startup (Screen.PrimaryScreen.Width & Height) and toss up a message at that
point.
 
That is what I mean. This is what I have come up with.

I place the following code in the form's Got_Focus event:

Dim screenHeight As Integer = Me.Bottom + Me.Top
Dim screenWidth As Integer = Me.Left + Me.Right
Dim txt As String = ""
Dim x As Integer

If screenHeight = 240 & screenWidth = 320 Then
' landscape mode
txt = "This program is designed to " + vbCrLf
txt = txt + "work in portrait mode only." + vbCrLf + vbCrLf
txt = txt + "Please reset to portrait mode and try again."

x = MessageBox.Show(txt, "Orientation Error!",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1)
Application.Exit()
ElseIf screenHeight = 320 & screenWidth = 240 Then
' portrait mode
End If


It appears to be working so far.


------------------------------------------
Noble D. Bell
AgForest Partners, Inc.



Whaqt do you mean? Have the app not load if the device is landscape or
something like that? You could always check the screen dimensions at
startup (Screen.PrimaryScreen.Width & Height) and toss up a message at that
point.
 
You can access the System.Windows.Forms.Screen.PrimaryScreen.Bounds rather
than working out the size from your form. Also rather than quitting and
giving the user instructions to change the orientation you can change it
yourself in code. If you are using .NETCF v2.0 use the
Microsoft.WindowsCE.Forms.SystemSettings.ScreenOrientation property, for
v1.0 there is a matching class in the Mobile In The Hand Community Edition:-
http://www.inthehand.com/WindowsMobile.aspx

Peter

--
Peter Foot
Device Application Development MVP
www.peterfoot.net | www.inthehand.com

Noble Bell said:
That is what I mean. This is what I have come up with.

I place the following code in the form's Got_Focus event:

Dim screenHeight As Integer = Me.Bottom + Me.Top
Dim screenWidth As Integer = Me.Left + Me.Right
Dim txt As String = ""
Dim x As Integer

If screenHeight = 240 & screenWidth = 320 Then
' landscape mode
txt = "This program is designed to " + vbCrLf
txt = txt + "work in portrait mode only." + vbCrLf + vbCrLf
txt = txt + "Please reset to portrait mode and try again."

x = MessageBox.Show(txt, "Orientation Error!",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1)
Application.Exit()
ElseIf screenHeight = 320 & screenWidth = 240 Then
' portrait mode
End If


It appears to be working so far.
 
Back
Top