C修改屏幕分辨率(Cmodifiesscreenresolution)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C#修改屏幕分辨率(C# modifies screen resolution)使用系统;
使用system.collections.generic;
使用ponentmodel;
使用系统数据;
使用系统图;
使用LINQ系统;
使用系统文本;
使用system.windows.forms;
使用system.runtime.interopservices;
命名空间设置屏幕分辨率
{
公共部分类Form1:形式
{
公共form1()
{
initializecomponent();
}
公共建设单位wm_syscommand = 0x0112;
公共建设单位sc_monitorpower = 0xf170;
【dllimport(“user32”)]
公共静态走读生IntPtr SendMessage(IntPtr hWnd的wmsg,uint wParam lParam,int);
枚举DMDO
{
默认值= 0,
D90 = 1,
D180 = 2,
d270 = 3
}
[ structlayout(layoutkind.sequential,字符集的字符集自动)]
DEVMODE结构
{
公共const int dm_displayfrequency = 0x400000;
公共const int dm_pelswidth = 0x80000;
公共const int dm_pelsheight = 0x100000;
公共const int dm_bitsperpel = 262144;
私人const int cchdevicename = 32;
私人const int cchformname = 32;
[ marshalas(unmanagedtype.byvaltstr,SizeConst = cchdevicename)]
dmdevicename字符串;
公共短dmspecversion;
公共短dmdriverversion;
公共短dmsize;
公共短dmdriverextra;
public int dmfields;
public int dmpositionx;
public int dmpositiony;
公共dmdisplayorientation DMDO;
public int dmdisplayfixedoutput;
公共短dmcolor;
公共短dmduplex;
公共短dmyresolution;
公共短dmttoption;
公共短dmcollate;
[ marshalas(unmanagedtype.byvaltstr,SizeConst = cchformname)]
dmformname字符串;
公共短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 ([in] ref devmode lpdevmode, int dwflags);
int dwidth = 0;
int dheight = 0;
private void getdis () / / 获取分辨率
{
size s = systeminformation.primarymonitorsize;
dwidth = s. width;
dheight = s. height;
lbldisinfo. text = dwidth.tostring () + "x" + dheight.tostring () + "像素";
}
private void form1 _ load (object sender, eventargs and)
{
getdis ();
changedis (1);
}
private void changedis (int i) / / 变换分辨率
{
int dvalue;
dvalue = trackbar1. value;
if (i = = 0)
{
switch (dvalue)
{
case 0: dwidth = 800; dheight = 600; break; case 1: dwidth = 1024; dheight = 768; break; case 2: dwidth = 1152; dheight = 864; break; case 3: dwidth = 1280; dheight = 600; break; case 4: dwidth = 1280; dheight = 720; break; case 5: dwidth = 1280; dheight = 768; break; case 6: dwidth = 1280; dheight = 760; break; case 7: dwidth = 1280; dheight = 1024; break; case 8: dwidth = 1400; dheight = 1050; break; case 9: dwidth = 1600; dheight = 900; break; case 10: dwidth = 1600; dheight = 1200; break; }
lbldisinfo. text = dwidth.tostring () + "x" + dheight.tostring () + "像素";
}
else
{
int dsum = dwidth + dheight;
switch (dsum)
{
houses 1400: trackbar1. value = 0; break;
houses, 1792: trackbar1. value = 1; break;
houses 2016: trackbar1. value = 2; break;
houses, 1880: trackbar1. value = 3; break;
houses 2000: trackbar1. value = 4; break;
houses 2048: trackbar1. value = 5; break;
houses 2240: trackbar1. value = 6; break;
houses 234: trackbar1. value = 7; break;
houses 2450: trackbar1. value = 8; break;
houses 2500: trackbar1. value = 9; break;
case: trackbar1 2800. value = 10; break;
}
}
}
private void trackbar1 _ scroll (object sends, eventargs (e) {
changedis (0);
}
private void button1 _ click (object sends, eventargs (e) {
long retval = 0;
devmode dm = new devmode ();
dm.dmsize = (short) marshal.sizeof (typeof (devmode));
dm.dmpelswidth = dwidth; / / 宽
dm.dmpelsheight = dheight; / / 高
dm.dmdisplayfrequency = 85; / / 刷新率
dm.dmfields = devmode.dm _ pelswidth | devmode.dm _ pelsheight | devmode.dm _ displayfrequency | devmode.dm _ bitsperpel;
retval = changedisplaysettings (ref dm, 0);
}
}
}。