/// <summary> /// 画面を回転 /// </summary> /// <param name="increment">回転量</param> /// <returns></returns> public int Rotate(int increment) { var deviceMode = this.Mode.Mode; //奇数量回転の場合は高さと幅を入れ替える if (increment % 2 == 1) { // swap width and height int temp = deviceMode.dmPelsHeight; deviceMode.dmPelsHeight = deviceMode.dmPelsWidth; deviceMode.dmPelsWidth = temp; } var newOrientation = (deviceMode.dmDisplayOrientation + increment) % 4; deviceMode.dmDisplayOrientation = newOrientation; var result = DisplayDevice.ChangeDisplaySettingsEx (this.Mode.Name, ref deviceMode, IntPtr.Zero, DisplayDevice.CDS_UPDATEREGISTRY, IntPtr.Zero); //DISP_CHANGE_SUCCESSFUL = 0: Indicates that the function succeeded. //DISP_CHANGE_BADMODE = -2: The graphics mode is not supported. //DISP_CHANGE_FAILED = -1: The display driver failed the specified graphics mode. //DISP_CHANGE_RESTART = 1: The computer must be restarted for the graphics mode to work. /* * if (NativeMethods.DISP_CHANGE_SUCCESSFUL != iRet) * { * // add exception handling here * }*/ if (increment != 0) { DisplayDevice.ChangeDisplaySettingsEx (this.Mode.Name, ref deviceMode, IntPtr.Zero, 0, IntPtr.Zero); } return(result); }