Example #1
0
        /// <summary>
        /// ChangeDisplayMode 更改系统的显示设置。
        /// </summary>    
        public static void ChangeDisplayMode(ScreenResolution screenResolution)
        {
            if (screenResolution.BitsPerPixels == 0 || screenResolution.DisplayFrequency == 0)
            {
                ScreenHelper.ChangeDisplayMode(screenResolution.Width, screenResolution.Height);
                return;
            }

            bool found = false;
            foreach (DisplayMode mode in ScreenHelper.GetSupportedDisplayModes())
            {
                if (mode.dmPelsWidth == screenResolution.Width && mode.dmPelsHeight == screenResolution.Height
                 && mode.dmDisplayFrequency == screenResolution.DisplayFrequency && mode.dmBitsPerPel == screenResolution.BitsPerPixels)
                {
                    found = true;
                    ScreenHelper.ChangeDisplayMode(mode);
                    break;
                }
            }

            if (!found)
            {
                throw new Exception("ScreenResolution settings Not Supported");
            }
        }