ARTICLE

How to change screen resolution in C#

Posted by Joshy George Articles | C# Language October 13, 2006
All programmers are facing common problem is how to change screen Resolution dynamically. In .Net 2005 it's very easy to change the screen resolution. Here I will explain you how can we get the Screen resolution and how we will change the resolution at dynamically and while unloading the page it will come as it was before. In dot net we can access the values of user's screen resolution through the Resolution class. It also affects all running (and minimized) programs.
Reader Level:
Download Files:
 

Introduction

It is a sample program It will demonstrate how to change resolution at runtime.

All programmers are facing common problem is how to change screen Resolution dynamically. In .Net 2005 it's very easy to change the screen resolution. Here I will explain you how can we get the screen resolution and how we will change the resolution dynamically and while unloading the page it will come as it was before. In .NET we can access the values of user's screen resolution through the Resolution class. It also affects all running (and minimized) programs.

Page_Load Code

Screen Srn = Screen.PrimaryScreen;

tempHeight = Srn.Bounds.Width;

tempWidth = Srn.Bounds.Height;

Page.ClientScript.RegisterStartupScript(this.GetType(), "Error", "<script type=\"text/javascript\">alert('" + "Your Current Resolution  is = " + tempHeight + " * " + tempWidth + "');</script>");

//if you want Automatically Change res.at page load. please uncomment this code.

 

if (tempHeight == 600)//if the system is 800*600 Res.then change to

{

FixHeight = 768;

FixWidth = 1024;

Resolution.CResolution ChangeRes = new Resolution.CResolution(FixHeight, FixWidth);

} 

Change Resoultion 

switch (cboRes.SelectedValue.ToString())

{

    case "800*600":

        FixHeight = 800;

        FixWidth = 600;

        Resolution.CResolution ChangeRes600 = new Resolution.CResolution(FixHeight, FixWidth);

        break;

 

    case "1024*768":

        FixHeight = 1024;

        FixWidth = 768;

        Resolution.CResolution ChangeRes768 = new Resolution.CResolution(FixHeight, FixWidth);

        break;

    case "1280*1024":

        FixHeight = 1280;

        FixWidth = 1024;

        Resolution.CResolution ChangeRes1024 = new Resolution.CResolution(FixHeight, FixWidth);

        break;

}

Login to add your contents and source code to this article
post comment
     

it is webbased only i want the window based

Posted by sunit kumar Jun 15, 2012

i need to view and change power plan settings in windows 7 using c#

Posted by suba ranjana Jun 05, 2012

i need to know how to implement this in windows application

Posted by Vasistan Sakkaravarthi Mar 14, 2012

hi i m making d website in wich i need dis resolution coding thnx alot

Posted by zara shaikh Mar 18, 2011

In fact he is using windows apis to change the resolution. There is no class "Resolution" in .Net. For all who want to get the code but don't want to register:
It's just a wrapper class called cResolution in an userdefined namespace Resolution that makes use of win32 api calls "EnumDisplaySettings" and "ChangeDisplaySettings". There are tons of examples for .net using this api, so no need to register. The opening paragraph "In .Net 2005 it's very easy to change the screen resolution" does only apply with an additional "if you already have a class which handles changing the resolution". Sorry man, but this is ridiculous.

Posted by dussel Dec 02, 2010
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Join a Chapter
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.