public static void ChangeResolution(ref DISPLAY_DEVICE device, int width, int height, short bits, int freq) { DEVMODE DevM = CreateDevMode(); bool enumResult = false; DisplayChangeResultCode changeResult = default(DisplayChangeResultCode); DevM.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY; enumResult = User32.EnumDisplaySettings(device.DeviceName, User32.ENUM_CURRENT_SETTINGS, ref DevM); DevM.dmPelsWidth = width; DevM.dmPelsHeight = height; DevM.dmBitsPerPel = bits; DevM.dmDisplayFrequency = freq; DevM.dmDeviceName = device.DeviceName; changeResult = (DisplayChangeResultCode)User32.ChangeDisplaySettingsEx(device.DeviceName, ref DevM, IntPtr.Zero, (0), IntPtr.Zero); if (changeResult != DisplayChangeResultCode.DISP_CHANGE_SUCCESSFUL) { throw new User32Exception("Failed to change resolution: " + changeResult.ToString()); } }
public static extern int ChangeDisplaySettingsEx(string lpDeviceName, ref DEVMODE lpDevMode, IntPtr HWND, int dwflags, IntPtr lParam);
public static extern bool EnumDisplaySettings(string lpszDeviceName, uint iModeNum, ref DEVMODE lpDevMode);
public static extern int ChangeDisplaySettings(ref DEVMODE lpDevMode, int dwFlags);
public DisplaySet(DISPLAY_DEVICE DisplayDevice, DEVMODE DeviceMode) { this.DisplayDevice = DisplayDevice; this.DeviceMode = DeviceMode; }