| The followingCodeTo modify the resolution and refresh frequency of a display: Using system; Using system. drawing; Using system. collections; Using system. componentmodel; Using system. Windows. forms; Using system. Data; Using system. runtime. interopservices; Namespace screenresolution { Public class form1: system. Windows. Forms. Form { Public Enum dmdo { Default = 0, D90 = 1, D180 = 2,
D270 = 3 } [Structlayout (layoutkind. Sequential, charset = charset. Auto)] Struct devmode { Public const int dm_displayfrequency = 0x400000; Public const int dm_pelswidth = 0x80000; Public const int dm_pelsheight = 0x100000; Private const int cchdevicename = 32; Private const int cchformname = 32; [Financialas (unmanagedtype. byvaltstr, sizeconst = cchdevicename)]
Public String dmdevicename; Public short dmspecversion; Public short dmdriverversion; Public short dmsize; Public short dmdriverextra; Public int dmfields; Public int dmpositionx; Public int dmpositiony; Public dmdo dmdisplayorientation; Public int dmdisplayfixedoutput; Public short dmcolor;
Public short dmduplex; Public short dmyresolution; Public short dmttoption; Public short dmcollate; [Financialas (unmanagedtype. byvaltstr, sizeconst = cchformname)] Public String dmformname; Public short 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 (devmode lpdevmode, int dwflags );
Static extern int changedisplaysettings ([in] ref devmode lpdevmode, int dwflags ); Private system. componentmodel. Container components = NULL; Public form1 () { Initializecomponent (); } Protected override void dispose (bool disposing) { If (disposing) { If (components! = NULL) {
Components. Dispose (); } } Base. Dispose (disposing ); } # Region windows Form Designer generated code Private void initializecomponent () { This. autoscalebasesize = new system. Drawing. Size (6, 14 ); This. clientsize = new system. Drawing. Size (292,273 ); This. Text = "example of changing the screen resolution "; }
# Endregion Static void main () { Form1 r = new form1 (); R. changeres (); Application. Run (New form1 ()); } Void changeres () { Form1 T = new form1 (); Long retval = 0; Devmode dm = new devmode (); DM. dmsize = (short) Marshal. sizeof (typeof (devmode )); DM. dmpelswidth = 1024;
DM. dmpelsheight = 768; DM. dmdisplayfrequency = 85; DM. dmfields = devmode. dm_pelswidth | devmode. dm_pelsheight | devmode. dm_displayfrequency; Retval = changedisplaysettings (ref DM, 0 ); } } } |