/// <summary> /// Change the current video mode to the specified mode. /// </summary> /// <param name="adapter">Video adapter information.</param> /// <param name="mode">New video mode.</param> /// <returns> /// <strong>true</strong> if the operation could be performed; <strong>false</strong> otherwise. /// </returns> public static bool ChangeVideoMode(VideoAdapterDeviceInfo adapter, VideoModeDeviceInfo mode) { const DeviceContext.NativeMethods.ChangeDisplaySettingsFlags flags = DeviceContext.NativeMethods.ChangeDisplaySettingsFlags.CDS_UPDATEREGISTRY | DeviceContext.NativeMethods.ChangeDisplaySettingsFlags.CDS_SET_PRIMARY; var result = ChangeVideoMode(adapter, mode, flags); return(result == DeviceContext.NativeMethods.DISP_CHANGE.DISP_CHANGE_SUCCESSFUL); }
/// <summary> /// Change the current video mode to the specified mode. /// </summary> /// <param name="adapter">The adapter.</param> /// <param name="newVideoMode">New video mode.</param> /// <param name="flags">Status indicators for changing / testing a video mode.</param> /// <returns> /// One of the values in the <see cref="DeviceContext.NativeMethods.DISP_CHANGE"/> enumeration that indicates the status. /// </returns> private static DeviceContext.NativeMethods.DISP_CHANGE ChangeVideoMode(VideoAdapterDeviceInfo adapter, VideoModeDeviceInfo newVideoMode, DeviceContext.NativeMethods.ChangeDisplaySettingsFlags flags) { var devMode = GdiPrint.DEVMODE.Empty; devMode.dmFields = GdiPrint.DEVMODE.DM.Position | GdiPrint.DEVMODE.DM.PelsWidth | GdiPrint.DEVMODE.DM.PelsHeight | GdiPrint.DEVMODE.DM.DisplayFlags | GdiPrint.DEVMODE.DM.BitsPerPixel | GdiPrint.DEVMODE.DM.DisplayFrequency; devMode.dmPelsWidth = newVideoMode.Size.Width; devMode.dmPelsHeight = newVideoMode.Size.Height; devMode.dmPosition.X = newVideoMode.Location.X; devMode.dmPosition.Y = newVideoMode.Location.Y; devMode.dmBitsPerPel = newVideoMode.BitsPerPixel; devMode.dmDisplayFrequency = newVideoMode.Frequency; return(DeviceContext.NativeMethods.ChangeDisplaySettingsEx(adapter.DisplayName, ref devMode, IntPtr.Zero, (int)flags, IntPtr.Zero)); }