.NET – Changing Screen Resolution

Last night I was working a project, and a feature was requested to have the program change the screen resolution to 1024×768, and then back to what the user had before they started the program. I figured, hey, .NET, it should be easy, right? First rule of computers…nothing can every be easy.

First order of business. Get the screen size of the screen before changing it, so I know what to change it back to.


&nbsp iOrigialScreenWidth = Screen.PrimaryScreen.Bounds.Width()
&nbsp iOrigialScreenHeight = Screen.PrimaryScreen.Bounds.Height()

Well you think you would be able to set those values as well as get them? Come on, that would be to easy.

The only way I could figure out how to change it was to revisit the good ol’ API. I found a class that someone has wrapped around the API calls to change the resolution, so I referenced that in my project, and was ready to go. At the top of the code “Imports Resolution” – Resolution was the name of the class.


&nbsp ‘ change to 1024×768 so the program fills screen
&nbsp Dim ChangeRes As CResolution
&nbsp ChangeRes = New Resolution.CResolution(1024, 768)

and to change it back again, on close of the program:

&nbsp ‘ change to original resolution
&nbsp Dim ChangeRes As CResolution
&nbsp ChangeRes = New Resolution.CResolution(iOrigialScreenWidth , iOrigialScreenHeight)

Well, anyway, here is the API Class (in C#). You would need to reference the Assembly in your project.

Source Code

So, the moral of the story, instead of using 6 lines of code to change the resolution back and forth, it takes 6 lines and referencing the API. Fun!

Advertisements

2 thoughts on “.NET – Changing Screen Resolution”

  1. This Project on Windows Resolution Change by C# has been a great help to me.But when run different machines sometimes gives errors.I would be eager to know them & if you could help me out how to recover them.

    Like

  2. This Project on Windows Resolution Change by C# has been a great help to me.But when run different machines sometimes gives errors.I would be eager to know them & if you could help me out how to recover them.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s