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
  • 相关阅读:
    从一个iOS毛头小子到现在的高级工程师, 我总结了一些经验,先跟大家分享一下一些好的资料
    iOS面试题---Objective_C语言特性:分类、扩展、代理、通知、KVO、KVC、属性
    200道iOS面试题面试题整理,底层、技术亮点公司需要的这里都有
    [iOS 开发] iOS 开发从菜鸟到高手?听听他们怎么说
    2020年面向iOS开发人员的知识点总结(更新中)
    OC项目转Swift指南
    来自老程序员的10条中肯建议
    面对职业瓶颈,iOS 开发人员应该如何突破?
    憨憨程序猿,不要让你的技术被简历埋没了
    总结:实现线程同步的八种方式
  • 原文地址:https://www.cnblogs.com/CharlesGrant/p/3650867.html
Copyright © 2011-2022 走看看