zoukankan      html  css  js  c++  java
  • #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
  • 相关阅读:
    MySQL主从复制
    Mysql解压版安装配置
    MySQL 多行数据合并 GROUP_CONCAT
    Java集合框架
    Redis 入门知识点
    事务
    Spring AOP 知识点入门
    Tomcat热部署和热加载
    Java的Socket通信简单实例
    nginx和tomcat配置负载均衡和session同步
  • 原文地址:https://www.cnblogs.com/CharlesGrant/p/3650867.html
Copyright © 2011-2022 走看看