Changing Screen Resolution through C#
-
I want to provide operators of my C# software the opportunity to change screen resolution to optimal settings (1024x768) for viewing this particular software. How do I change screen resolution (and maintain those changed settings), should the user opt to do so? -- modified at 11:08 Tuesday 20th December, 2005 I should have added the following. The computer that will be running the program is, in this case, a dedicated machine. It's purpose is basically to run the software I'm developing. As such, it makes a certain sense to have the display settings optimal for the particular application-should the operator opt to set them that way. The operator is under no obligation to set the computer to those optimal settings and will have the option to not see the message box again after the initial run of the program.
-
I want to provide operators of my C# software the opportunity to change screen resolution to optimal settings (1024x768) for viewing this particular software. How do I change screen resolution (and maintain those changed settings), should the user opt to do so? -- modified at 11:08 Tuesday 20th December, 2005 I should have added the following. The computer that will be running the program is, in this case, a dedicated machine. It's purpose is basically to run the software I'm developing. As such, it makes a certain sense to have the display settings optimal for the particular application-should the operator opt to set them that way. The operator is under no obligation to set the computer to those optimal settings and will have the option to not see the message box again after the initial run of the program.
You can do this by using P/Invoke to access the Win32 API from your C# code. Have a look at the ChangeDisplaySettings function and the DEVMODE structure. You will need to create the DEVMODE structure in your code and use DllImport to call ChangeDisplaySettings. The following link documents the DEVMODE structure. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_8nle.asp[^] I hope this helps. Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
-
I want to provide operators of my C# software the opportunity to change screen resolution to optimal settings (1024x768) for viewing this particular software. How do I change screen resolution (and maintain those changed settings), should the user opt to do so? -- modified at 11:08 Tuesday 20th December, 2005 I should have added the following. The computer that will be running the program is, in this case, a dedicated machine. It's purpose is basically to run the software I'm developing. As such, it makes a certain sense to have the display settings optimal for the particular application-should the operator opt to set them that way. The operator is under no obligation to set the computer to those optimal settings and will have the option to not see the message box again after the initial run of the program.
What you're doing is not recommended, and, in fact, actively discouraged. Changing system-wide settings affects other applications that are running and also affects the layout of the desktop. Remember, Windows is a shared system, running multiple applications at once. You have to make sure you app works and plays nice with others. Changing system-wide settings so your app looks good, can make another app running at the same time look bad. I know if you did that to my machine while I'm working in Maya at 1900x1440, I'd be heading straight for Add/Remove Programs and dumping your app. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
What you're doing is not recommended, and, in fact, actively discouraged. Changing system-wide settings affects other applications that are running and also affects the layout of the desktop. Remember, Windows is a shared system, running multiple applications at once. You have to make sure you app works and plays nice with others. Changing system-wide settings so your app looks good, can make another app running at the same time look bad. I know if you did that to my machine while I'm working in Maya at 1900x1440, I'd be heading straight for Add/Remove Programs and dumping your app. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
Dave Kreskowiak wrote:
I know if you did that to my machine while I'm working in Maya at 1900x1440, I'd be heading straight for Add/Remove Programs and dumping your app.
In general, agreed. THe only time forcing a resolution should be allowed is in full screen mode, and then be sure to restore the settings when the user closes or alt-tabs out of your program.