Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. Screen Orientation

Screen Orientation

Scheduled Pinned Locked Moved Mobile
hardwarehelpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CodingYoshi
    wrote on last edited by
    #1

    Hello, I want to handle the event when the screen orientation changes. I searched the web but nothing. I want to put my code for each orientation based on the orientation. Is there any event that I can/should handle? I was thinking of capturing the orientation hardware's button pressed event but could not find it. Thanks for your help, CodingYoshi

    C R 2 Replies Last reply
    0
    • C CodingYoshi

      Hello, I want to handle the event when the screen orientation changes. I searched the web but nothing. I want to put my code for each orientation based on the orientation. Is there any event that I can/should handle? I was thinking of capturing the orientation hardware's button pressed event but could not find it. Thanks for your help, CodingYoshi

      C Offline
      C Offline
      Christopher Fairbairn
      wrote on last edited by
      #2

      Hi CodingYoshi,

      CodingYoshi wrote:

      I want to handle the event when the screen orientation changes. I searched the web but nothing.

      What language are you developing in? When the orientation changes the size of your fullscreen window will automatically change. So one way to detect changes is to handle the window size changed event or window message that occurs in your chosen framework. If you need to tell if you are in portrait or landscape mode you can determine this by then checking if the current window width is greater than the height. If for some reason you actually need to determine the true orientation of the device (i.e. 0, 90, 180, 270 degrees) you can do this but the answer is a little different depending upon your programming language/environment of choice. Hope this helps, Christopher Fairbairn

      C 2 Replies Last reply
      0
      • C Christopher Fairbairn

        Hi CodingYoshi,

        CodingYoshi wrote:

        I want to handle the event when the screen orientation changes. I searched the web but nothing.

        What language are you developing in? When the orientation changes the size of your fullscreen window will automatically change. So one way to detect changes is to handle the window size changed event or window message that occurs in your chosen framework. If you need to tell if you are in portrait or landscape mode you can determine this by then checking if the current window width is greater than the height. If for some reason you actually need to determine the true orientation of the device (i.e. 0, 90, 180, 270 degrees) you can do this but the answer is a little different depending upon your programming language/environment of choice. Hope this helps, Christopher Fairbairn

        C Offline
        C Offline
        CodingYoshi
        wrote on last edited by
        #3

        Hi Christopher, Thanks for the reply. I am using .NET (VB, C#, C++). Your suggestions definitely help and I will try them and let you know if I run into trouble. Thanks, CodingYoshi

        C 1 Reply Last reply
        0
        • C CodingYoshi

          Hello, I want to handle the event when the screen orientation changes. I searched the web but nothing. I want to put my code for each orientation based on the orientation. Is there any event that I can/should handle? I was thinking of capturing the orientation hardware's button pressed event but could not find it. Thanks for your help, CodingYoshi

          R Offline
          R Offline
          Ravenet
          wrote on last edited by
          #4

          Hi Guy I Had doen this in my project. we want to create a custom event eith Platform Invoke. i means like this u create this P/Invoke mthoed [DllImport("coredll.dll", SetLastError=true)] private static extern int ChangeDisplaySettingsEx( string lpszDeviceName, byte[] lpDevMode, IntPtr hwnd, CDS dwflags, IntPtr lParam); after create a DEMODE class like this internal class DEVMODE { public const short Size = 192; private byte[] mData; public DEVMODE() { mData = new byte[Size]; BitConverter.GetBytes((short)Size).CopyTo(mData, 68); } public byte[] ToByteArray() { return mData; } public DM Fields { get { return (DM)BitConverter.ToInt32(mData, 72); } set { BitConverter.GetBytes((int)value).CopyTo(mData, 72); } } public int DisplayOrientation { get { return BitConverter.ToInt32(mData, 188); } set { BitConverter.GetBytes(value).CopyTo(mData, 188); } } } [Flags()] internal enum DM { ORIENTATION = 0x00000001, PAPERSIZE = 0x00000002, PRINTQUALITY = 0x00000400, COLOR = 0x00000800, BITSPERPEL = 0x00040000, PELSWIDTH = 0x00080000, PELSHEIGHT = 0x00100000, DISPLAYORIENTATION = 0x00800000, DISPLAYQUERYORIENTATION = 0x01000000, } then let's crate a method , within that create object above class and call Above P/Invoke methods and pass arugs. If P/Invoke method return >0 when get success result from the OS, after get >0 u must inove ur event next line. and od ur work. i hope this is help to you. Thanks

          Cheers RRave MCTS,MCPD

          1 Reply Last reply
          0
          • C CodingYoshi

            Hi Christopher, Thanks for the reply. I am using .NET (VB, C#, C++). Your suggestions definitely help and I will try them and let you know if I run into trouble. Thanks, CodingYoshi

            C Offline
            C Offline
            Christopher Fairbairn
            wrote on last edited by
            #5

            Within your .NET Compact Framework application you can handle the OnSize event for your form, when the device changes orientations it will cause the form to be resized and by comparing the the width to height ratio you can determine if the device is in portrait or landscape mode. On a Windows Mobile 5.0 or higher device you may also like to investigate the SystemState.DisplayRotation property (http://msdn2.microsoft.com/en-us/library/microsoft.windowsmobile.status.systemstate.displayrotation.aspx[^])

            Windows Mobile Development blog http://www.christec.co.nz/blog/

            1 Reply Last reply
            0
            • C Christopher Fairbairn

              Hi CodingYoshi,

              CodingYoshi wrote:

              I want to handle the event when the screen orientation changes. I searched the web but nothing.

              What language are you developing in? When the orientation changes the size of your fullscreen window will automatically change. So one way to detect changes is to handle the window size changed event or window message that occurs in your chosen framework. If you need to tell if you are in portrait or landscape mode you can determine this by then checking if the current window width is greater than the height. If for some reason you actually need to determine the true orientation of the device (i.e. 0, 90, 180, 270 degrees) you can do this but the answer is a little different depending upon your programming language/environment of choice. Hope this helps, Christopher Fairbairn

              C Offline
              C Offline
              CodingYoshi
              wrote on last edited by
              #6

              Hi Christopher, The only event I found that has anything to do with the size is Resize. However, this event is not raised when orientation changes. None of the other events look useful to me. Any other ideas? Thanks, CodingYoshi

              C 1 Reply Last reply
              0
              • C CodingYoshi

                Hi Christopher, The only event I found that has anything to do with the size is Resize. However, this event is not raised when orientation changes. None of the other events look useful to me. Any other ideas? Thanks, CodingYoshi

                C Offline
                C Offline
                Christopher Fairbairn
                wrote on last edited by
                #7

                Hi CodingYoshi,

                CodingYoshi wrote:

                The only event I found that has anything to do with the size is Resize. However, this event is not raised when orientation changes. None of the other events look useful to me.

                Hmm what operating system/mobile device type are you targeting? Hope this helps, Christopher Fairbairn

                Windows Mobile Development blog http://www.christec.co.nz/blog/

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups