I have done a project in c# winforms. I want to set the resolution of the screen to 1680 x 1050, when the application is run in any pc. How to do it ?
3 Answers
As the others already mentioned you shouldn't change the resolution automatically, cause the user set it to a specific resolution he likes (or his hardware works best on).
So instead of changing the resolution you should change your application. Use TableLayoutPanel, FlowLayoutPanel and / or SplitContainer. Set the Anchor and Dock properties of your Controls and think about setting the MinimumSize and MaximumSize of each control within your application.
This way your application can automatically scale between different resolutions and the user can take the one he likes.
Last but not least, your application should not only consider to take care about the resolution the user selected, it should also take care about the selected dpi settings. Which one you should care of are described in the Windows UX Guide (site 592).
-
Just down voted. Don't get me wrong, the answer you provided is very informative, but you didn't answer the question. Personally, I want to know this for a personal project that I'm not planning on distributing, so whether other people's displays support the resolution isn't a concern of mine (I do realise that the original poster did say "run in any pc", but for me, a correct answer should give the above advice, but still answer the question) Commented Aug 15, 2013 at 14:20
-
@DarkHippo: In that case, don't down vote. Simply ask a new question, refer to this one and say what is different in your case.– OliverCommented Aug 16, 2013 at 6:06
I would advice you to not do these kind of things. The screen resolution is set by the user and this is something you shouldn't change automatically. It is just as bad as changing the color scheme, sound scheme or any other user based preferences without the user knowing anything about it, let alone wants to let your program to do. At least show a dialog and let the user choose what to do.
Having said that, here's an example on how to do this.
Well, he is not saying his application will be changing other systems' resolutions. You shouldn't change the screen resolution on other people's computers; however, it may be necessary for a user to change his own resolution through a separate utility (for different reasons). That is my case right now, so I had to write a simple utility in C# to accomplish that by using InteropServices. Call ChangeDisplaySettings. Here's the declaration:
[DllImport("user32.dll")]
public static extern int ChangeDisplaySettings(
ref DEVMODE devMode, int flags);