#region 自适应屏幕分辨率

        #region 自适应屏幕分辨率

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct DEVMODE
        {
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
            public string dmDeviceName;
            public short dmSpecVersion;
            public short dmDriverVersion;
            public short dmSize;
            public short dmDriverExtra;
            public int dmFields;
            public short dmOrientation;
            public short dmPaperSize;
            public short dmPaperLength;
            public short dmPaperWidth;
            public short dmScale;
            public short dmCopies;
            public short dmDefaultSource;
            public short dmPrintQuality;
            public short dmColor;
            public short dmDuplex;
            public short dmYResolution;
            public short dmTTOption;
            public short dmCollate;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
            public string dmFormName;
            public short dmLogPixels;
            public int dmBitsPerPel;
            public int dmPelsWidth;
            public int dmPelsHeight;
            public int dmDisplayFlags;
            public int dmDisplayFrequency;
        }

[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);

public static void ChangeRes(int width, int height)
        {
            DEVMODE devM = new DEVMODE();
            devM.dmSize = (short)Marshal.SizeOf(typeof(DEVMODE));
            bool mybool;
            mybool = EnumDisplaySettings(null, 0, ref devM);
            devM.dmPelsHeight = height;
            devM.dmPelsWidth = width;
            devM.dmDisplayFrequency = 75;
            devM.dmBitsPerPel = 32;
            long result = ChangeDisplaySettings(ref devM, 0);
        }

//客户端// 获取屏幕分辨率
        protected int OriginalScreenSizeWidth = Screen.PrimaryScreen.Bounds.Width;
        protected int OriginalScreenSizeHeight = Screen.PrimaryScreen.Bounds.Height;

void frmMachineSpecific_FormClosing(object sender, FormClosingEventArgs e)
        {
            //退出时还原分辨率
            ChangeRes(OriginalScreenSizeWidth, OriginalScreenSizeHeight);
        }
        #endregion

上一篇:Javascript转义字符串中的特殊字符处理


下一篇:java转换 HTML字符实体,java特殊字符转义字符串