C# 窗口大小及屏幕分辨率操作
1. 获取屏幕分辨率
using System.Windows.Forms;
A. 获取屏幕分辨率
int SH = Screen.PrimaryScreen.Bounds.Height;
int SW = Screen.PrimaryScreen.Bounds.Width;
B. 通过调用DLL改变屏幕分辨率
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int ChangeDisplaySettings([In] ref DEVMODE lpDevMode, int dwFlags);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern bool EnumDisplaySettings(string lpszDeviceName, Int32 iModeNum, ref DEVMODE lpDevMode);
void ChangeResolution()
{
DEVMODE DevM = new DEVMODE();
DevM.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
bool mybool;
mybool = EnumDisplaySettings(null, 0, ref DevM);
DevM.dmPelsWidth = 1024;//宽
DevM.dmPelsHeight = 768;//高
DevM.dmDisplayFrequency = 60;//刷新频率
DevM.dmBitsPerPel = 32;//颜色象素
long result = ChangeDisplaySettings(ref DevM, 0);
}
2.WinForm窗口操作
this.WindowState = FormWindowState.Maximized; //使Winform启动时直接最大化