您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 临沂分类信息网,免费分类信息发布

C# 代码调整屏幕分辨率

2024/3/16 10:33:53发布24次查看
using system;
using system.collections.generic;
using system.componentmodel;
using system.data;
using system.drawing;
using system.linq;
using system.text;
using system.windows.forms;
using system.runtime.interopservices;
namespace 解决分辨率
{
    public partial class form1 : form
    {
        //保存当前屏幕分辨率
        int i = screen.primaryscreen.bounds.width;
int j = screen.primaryscreen.bounds.height;
        public form1()
        {
            initializecomponent();
        }
        [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);
        void changeres()
        {
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);
        }
        void fuyuan()
        {
            devmode devm = new devmode();
            devm.dmsize = (short)marshal.sizeof(typeof(devmode));
            bool mybool;
            mybool = enumdisplaysettings(null, 0, ref devm);
            devm.dmpelswidth = i;//恢复宽
            devm.dmpelsheight =j;//恢复高
            devm.dmdisplayfrequency = 60;//刷新频率
            devm.dmbitsperpel = 32;//颜色象素
            long result = changedisplaysettings(ref devm, 0);
        }
        private void form1_load(object sender, eventargs e)
        {
            changeres();
        }
private void button1_click(object sender, eventargs e)
        {
            fuyuan();
            this.close();
}
临沂分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录