C#的设计者们真是可恨,弄了些不错的接口就发懒了,也不扩充扩充C#自己的库!!什么事情都要调API,这里给大家介绍一下用API改变分辨率的东东(要改变的时候调用SetSize(int x,int y);) using System; using System.Runtime.InteropServices;
public class ScreenSet { public enum DMDO { DEFAULT = 0, D90 = 1, D180 = 2, D270 = 3 }
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)] struct DEVMODE { public const int DM_DISPLAYFREQUENCY = 0x400000; public const int DM_PELSWIDTH = 0x80000; public const int DM_PELSHEIGHT = 0x100000; private const int CCHDEVICENAME = 32; private const int CCHFORMNAME = 32;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=CCHDEVICENAME)] public string dmDeviceName; public short dmSpecVersion; public short dmDriverVersion; public short dmSize; public short dmDriverExtra; public int dmFields;
public int dmPositionX; public int dmPositionY; public DMDO dmDisplayOrientation; public int dmDisplayFixedOutput;
public short dmColor; public short dmDuplex; public short dmYResolution; public short dmTTOption; public short dmCollate; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=CCHFORMNAME)] public string dmFormName; public short dmLogPixels; public int dmBitsPerPel; public int dmPelsWidth; public int dmPelsHeight; public int dmDisplayFlags; public int dmDisplayFrequency; public int dmICMMethod; public int dmICMIntent; public int dmMediaType; public int dmDitherType; public int dmReserved1; public int dmReserved2; public int dmPanningWidth; public int dmPanningHeight; }
[DllImport("user32.dll", CharSet=CharSet.Auto)] //static extern int ChangeDisplaySettings( DEVMODE lpDevMode, int dwFlags);
static extern int ChangeDisplaySettings( [In] ref DEVMODE lpDevMode, int dwFlags); private System.ComponentModel.Container components = null; public static void SetSize(int x,int y) { Form1 t = new Form1(); long RetVal=0; DEVMODE dm = new DEVMODE(); dm.dmSize= (short)Marshal.SizeOf(typeof(DEVMODE)); dm.dmPelsWidth = x; dm.dmPelsHeight= y; dm.dmDisplayFrequency=85; dm.dmFields = DEVMODE.DM_PELSWIDTH | DEVMODE.DM_PELSHEIGHT | DEVMODE.DM_DISPLAYFREQUENCY; RetVal = ChangeDisplaySettings(ref dm, 0); } }