public static void ChangeDisplayMode(int width, int heigth) { DisplayMode?target = null; foreach (DisplayMode mode in ScreenHelper.GetSupportedDisplayModes()) { if (mode.dmPelsWidth == width && mode.dmPelsHeight == heigth) { if (target == null) { target = mode; } else { if (mode.dmDisplayFrequency > target.Value.dmDisplayFrequency || mode.dmBitsPerPel > target.Value.dmBitsPerPel) { target = mode; } } } } if (target == null) { throw new Exception("ScreenResolution settings Not Supported"); } ScreenHelper.ChangeDisplayMode(target.Value); }
/// <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"); } }