Esempio n. 1
0
        public static int GetAngle()
        {
            int rotation = 0;

            DisplaySettings set = DisplayManager.GetCurrentSettings();

            switch (set.Orientation)
            {
            case Orientation.Default:
                rotation = 0;
                break;

            case Orientation.Clockwise90:
                rotation = 90;
                break;

            case Orientation.Clockwise180:
                rotation = 180;
                break;

            case Orientation.Clockwise270:
                rotation = 270;
                break;
            }

            return(rotation);
        }
Esempio n. 2
0
        /// <summary>
        /// Rotates the screen from its current location by 90 degrees either clockwise or anti-clockwise.
        /// </summary>
        /// <param name="clockwise">Set to true to rotate the screen 90 degrees clockwise from its current location, or false to rotate it anti-clockwise.</param>
        public static int RotateScreen(bool clockwise)
        {
            int rotation = 0;

            DisplaySettings set = DisplayManager.GetCurrentSettings();

            int tmp = set.Height;

            set.Height = set.Width;
            set.Width  = tmp;

            if (clockwise)
            {
                set.Orientation++;
            }
            else
            {
                set.Orientation--;
            }

            if (set.Orientation < Orientation.Default)
            {
                set.Orientation = Orientation.Clockwise270;
            }
            else if (set.Orientation > Orientation.Clockwise270)
            {
                set.Orientation = Orientation.Default;
            }

            SetDisplaySettings(set);

            switch (set.Orientation)
            {
            case Orientation.Default:
                rotation = 0;
                break;

            case Orientation.Clockwise90:
                rotation = 90;
                break;

            case Orientation.Clockwise180:
                rotation = 180;
                break;

            case Orientation.Clockwise270:
                rotation = 270;
                break;
            }

            return(rotation);
        }
Esempio n. 3
0
        /// <summary>
        /// Changes the current display settings with the new settings provided. May throw InvalidOperationException if failed. Check the exception message for more details.
        /// </summary>
        /// <param name="set">The new settings.</param>
        /// <remarks>
        /// Internally calls ChangeDisplaySettings() native function.
        /// </remarks>
        public static void SetDisplaySettings(DisplaySettings set)
        {
            SafeNativeMethods.DEVMODE mode = GetDeviceMode();

            mode.dmPelsWidth          = (uint)set.Width;
            mode.dmPelsHeight         = (uint)set.Height;
            mode.dmDisplayOrientation = (uint)set.Orientation;
            mode.dmBitsPerPel         = (uint)set.BitCount;
            mode.dmDisplayFrequency   = (uint)set.Frequency;

            DisplayChangeResult result = (DisplayChangeResult)SafeNativeMethods.ChangeDisplaySettings(ref mode, 0);

            string   msg = null;
            Assembly asm = Assembly.GetExecutingAssembly();

            switch (result)
            {
            case DisplayChangeResult.BadDualView:
                msg = InvalidOperation_Disp_Change_BadDualView;
                break;

            case DisplayChangeResult.BadParam:
                msg = InvalidOperation_Disp_Change_BadParam;
                break;

            case DisplayChangeResult.BadFlags:
                msg = InvalidOperation_Disp_Change_BadFlags;
                break;

            case DisplayChangeResult.NotUpdated:
                msg = InvalidOperation_Disp_Change_NotUpdated;
                break;

            case DisplayChangeResult.BadMode:
                msg = InvalidOperation_Disp_Change_BadMode;
                break;

            case DisplayChangeResult.Failed:
                msg = InvalidOperation_Disp_Change_Failed;
                break;

            case DisplayChangeResult.Restart:
                msg = InvalidOperation_Disp_Change_Restart;
                break;
            }

            if (msg != null)
            {
                throw new InvalidOperationException(msg);
            }
        }
Esempio n. 4
0
        public static int ReverseScreen()
        {
            int             rotation = 0;
            DisplaySettings set      = DisplayManager.GetCurrentSettings();

            set.Orientation += 2;

            if (set.Orientation == Orientation.Clockwise270 + 2)
            {
                set.Orientation = Orientation.Clockwise90;
            }
            else if (set.Orientation == Orientation.Clockwise180 + 2)
            {
                set.Orientation = Orientation.Default;
            }

            SetDisplaySettings(set);

            switch (set.Orientation)
            {
            case Orientation.Default:
                rotation = 0;
                break;

            case Orientation.Clockwise90:
                rotation = 90;
                break;

            case Orientation.Clockwise180:
                rotation = 180;
                break;

            case Orientation.Clockwise270:
                rotation = 270;
                break;
            }

            return(rotation);
        }