tags:

views:

246

answers:

2

I want to change screen resolution with c# code in desktop application.

A: 

You can't do it by build in classes in C#/.net, but you can do it by win api, it is explained here. Then go to pinvoke.net or create your p/invoke methods manually.

Andrey
+2  A: 

This is a similar question to "I want to change the clock" or "I want to change the user password" or "I want to change the Windows theme". An application program has no business making such system configuration changes, accordingly it isn't wrapped by the .NET framework.

You can do it, but it will require P/Invoke. Use ChangeDisplaySettingsEx(). Not exactly easy to use, nor very safe to use. Lots of LCD panels only look good in one particular resolution, the one that the user selected. Picking a resolution that the monitor cannot support produces a black screen and the three-finger salute. Smoke in the good old days.

Hans Passant
You are wrong about "having no business" making such system changes. What if the user wants a nice, simple, one-button way to toggle between screen resolutions? If it were up to you, that would not be allowed. Second, the fact that it has not been wrapped in .NET doesn't necessarily imply that it should not be used. If anything, the fact that there is an API at all to do it shows you that it is meant for an application to make the change to that system setting. So that's a -1 for making assumptions and +1 for providing the solution :)
Erich Mirabal
Hmya, I'm channeling the opinion of Microsoft here. One I merely happen to agree with. A user can simply right-click the desktop, I've never noticed any asking for a button.
Hans Passant