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.
  iOrigialScreenWidth = Screen.PrimaryScreen.Bounds.Width()
  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.
  ‘ change to 1024×768 so the program fills screen
  Dim ChangeRes As CResolution
  ChangeRes = New Resolution.CResolution(1024, 768)
and to change it back again, on close of the program:
  ‘ change to original resolution
  Dim ChangeRes As CResolution
  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.
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!
2 replies on “.NET – Changing Screen Resolution”
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.
LikeLike
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.
LikeLike