How to set windows screen resolution using windows c # app

I made a project in winforms C #. I want to set the screen resolution to 1680 x 1050 when the application is launched on any PC. How to do it?

+2


a source to share


4 answers


As mentioned above, you shouldn't automatically change the resolution by forcing the user to set it to a specific resolution that they like (or their hardware works best).

So instead of changing the resolution, you should change your app. Use TableLayoutPanel , FlowLayoutPanel and / or SplitContainer . Set the Anchor and Dock properties of your Controls and thinks about setting the MinimumSize and MaximumSize of each control in your application.



This way, your app can automatically scale between different resolutions and the user can take the one they like.

Last but not least, your application should not only take care of the user's selected resolution, but also take care of the selected dpi settings. The one you need to take care of is described in the Windows UX Guide (site 592).

+5


a source


I would advise you not to do this kind of thing. The screen resolution is user-definable, and this is something you shouldn't automatically change. This is as bad as changing the color scheme, sound scheme, or any other custom settings without the user knowing anything about it, let alone letting your program do it. At least show the dialog and let the user choose what to do.
Having said that, here's an example on how to do it .



+4


a source


This article explains it pretty well:

http://www.codeproject.com/KB/cs/csdynamicscrres.aspx

+3


a source


Well, he is not saying that his application will change the permissions of other systems. You must not change the screen resolution on other people's computers; however, the user may need to change their own resolution using a separate utility (for various reasons). This is my business right now, so I had to write a simple C # utility to do this using InteropServices. Call ChangeDisplaySettings. Here's the declaration:

[DllImport("user32.dll")]
public static extern int ChangeDisplaySettings(
ref DEVMODE devMode, int flags);

      

+3


a source







All Articles