Beispiel #1
0
 public static bool RotateScreen(RotateDegress degress)
 {
     var rotate = new Rotate();
     bool allOk = true;
     foreach (var screen in Screen.AllScreens)
     {
         if (rotate.RotateScreen(degress, screen.DeviceName) == RotateResult.RotateFailed) allOk = false;
     }
     return allOk;
 }
Beispiel #2
0
        // ReSharper restore InconsistentNaming

        public RotateResult RotateScreen(RotateDegress pRotateDegrees, string deviceName = null)
        {
            var dm = new DEVMODE {
                dmDeviceName = new string((char)0, 32), dmFormName = new string((char)0, 32)
            };

            dm.dmSize = Convert.ToInt16(Marshal.SizeOf(dm));

            if ((UnsafeNativeMethods.EnumDisplaySettings(deviceName, ENUM_CURRENT_SETTINGS, ref dm) != 0))
            {
                // determine unrotated pixel sizes
                switch ((RotateDegress)dm.dmDisplayOrientation)
                {
                case RotateDegress.Degrees90:
                case RotateDegress.Degrees270:
                    SwapExtents(ref dm.dmPelsHeight, ref dm.dmPelsWidth);
                    break;
                }

                // set rotation parameters
                dm.dmDisplayOrientation = Convert.ToInt16(pRotateDegrees);
                switch (pRotateDegrees)
                {
                case RotateDegress.Degrees90:
                case RotateDegress.Degrees270:
                    SwapExtents(ref dm.dmPelsHeight, ref dm.dmPelsWidth);
                    break;
                }
                dm.dmFields = DM_DISPLAYORIENTATION | DM_PELSHEIGHT | DM_PELSWIDTH;

                // query change
                var rotRet = (RotateResult)UnsafeNativeMethods.ChangeDisplaySettings(ref dm, CDS_TEST);

                if (rotRet == RotateResult.RotateFailed)
                {
                    return(RotateResult.RotateFailed);
                }
                //enact change
                rotRet = (RotateResult)UnsafeNativeMethods.ChangeDisplaySettings(ref dm, CDS_UPDATEREGISTRY);
                switch (rotRet)
                {
                case RotateResult.RotateSuccessful:
                case RotateResult.RotateRequiresRestart:
                    return(rotRet);

                default:
                    return(RotateResult.RotateFailed);
                }
            }
            else
            {
                return(RotateResult.RotateFailed);
            }
        }
Beispiel #3
0
        public static bool RotateScreen(RotateDegress degress)
        {
            var  rotate = new Rotate();
            bool allOk  = true;

            foreach (var screen in Screen.AllScreens)
            {
                if (rotate.RotateScreen(degress, screen.DeviceName) == RotateResult.RotateFailed)
                {
                    allOk = false;
                }
            }
            return(allOk);
        }
Beispiel #4
0
        // ReSharper restore InconsistentNaming
        public RotateResult RotateScreen(RotateDegress pRotateDegrees, string deviceName = null)
        {
            var dm = new DEVMODE { dmDeviceName = new string((char)0, 32), dmFormName = new string((char)0, 32) };
            dm.dmSize = Convert.ToInt16(Marshal.SizeOf(dm));

            if ((UnsafeNativeMethods.EnumDisplaySettings(deviceName, ENUM_CURRENT_SETTINGS, ref dm) != 0))
            {
                // determine unrotated pixel sizes
                switch ((RotateDegress)dm.dmDisplayOrientation)
                {
                    case RotateDegress.Degrees90:
                    case RotateDegress.Degrees270:
                        SwapExtents(ref dm.dmPelsHeight, ref dm.dmPelsWidth);
                        break;
                }

                // set rotation parameters
                dm.dmDisplayOrientation = Convert.ToInt16(pRotateDegrees);
                switch (pRotateDegrees)
                {
                    case RotateDegress.Degrees90:
                    case RotateDegress.Degrees270:
                        SwapExtents(ref dm.dmPelsHeight, ref dm.dmPelsWidth);
                        break;
                }
                dm.dmFields = DM_DISPLAYORIENTATION | DM_PELSHEIGHT | DM_PELSWIDTH;

                // query change
                var rotRet = (RotateResult)UnsafeNativeMethods.ChangeDisplaySettings(ref dm, CDS_TEST);

                if (rotRet == RotateResult.RotateFailed)
                {
                    return RotateResult.RotateFailed;
                }
                //enact change
                rotRet = (RotateResult)UnsafeNativeMethods.ChangeDisplaySettings(ref dm, CDS_UPDATEREGISTRY);
                switch (rotRet)
                {
                    case RotateResult.RotateSuccessful:
                    case RotateResult.RotateRequiresRestart:
                        return rotRet;
                    default:
                        return RotateResult.RotateFailed;
                }
            }
            else
            {
                return RotateResult.RotateFailed;
            }
        }