Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

change screen resolution in C#

152 views
Skip to first unread message

Ed Hochberg

unread,
Feb 9, 2010, 6:39:09 PM2/9/10
to
Hi all, I found the following code on the web. It says it is for C#. Problem
is that it seems to be for ASP (it uses the Page_Load procedure) and I need
it for a regular Windows form. can anyone suggest how it may be modified for
my needs.

Thanks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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;

}

Scott M.

unread,
Feb 9, 2010, 6:47:59 PM2/9/10
to
While I'm not familiar with all of the code you show, no ASP .NET code can
change a user's screen resolution. You can detect what resolution they have
in JavaScript (and the code you've shown uses ASP .NET C# to generate
client-side JavaScript that is sent to the browser), but you can't change
it.

I would think that to change the screen resolution in a Windows app., you'd
need to access a Windows API.

-Scott


"Ed Hochberg" <EdHoc...@discussions.microsoft.com> wrote in message
news:6F9C4CED-AF25-44D2...@microsoft.com...

Arne Vajhøj

unread,
Feb 9, 2010, 8:18:32 PM2/9/10
to
On 09-02-2010 18:39, Ed Hochberg wrote:
> Hi all, I found the following code on the web. It says it is for C#. Problem
> is that it seems to be for ASP (it uses the Page_Load procedure) and I need
> it for a regular Windows form. can anyone suggest how it may be modified for
> my needs.

Call the native function ChangeDisplaySettingsEx via DllImport etc..

Arne

Michael C

unread,
Feb 9, 2010, 11:16:42 PM2/9/10
to
"Ed Hochberg" <EdHoc...@discussions.microsoft.com> wrote in message
news:6F9C4CED-AF25-44D2-B76B-
> case "800*600":
> case "1024*768":
> case "1280*1024":

That's the worst code I've seen for a while at least. :-)


Chris Dunaway

unread,
Feb 11, 2010, 3:11:39 PM2/11/10
to
On Feb 9, 5:39 pm, Ed Hochberg <EdHochb...@discussions.microsoft.com>
wrote:

Arne showed you the Windows API call to change the screen resolution,
but please don't do that! The user has set their resolution to what
they like and you should not change it! You might have the intent of
changing it back when you are through, but if your program crashes,
then the user will have to change it back manually.

Generally speaking, it is bad form to change any of the user's desktop
settings.

Arne Vajhøj

unread,
Feb 11, 2010, 9:31:13 PM2/11/10
to
On 11-02-2010 15:11, Chris Dunaway wrote:
> Arne showed you the Windows API call to change the screen resolution,
> but please don't do that! The user has set their resolution to what
> they like and you should not change it! You might have the intent of
> changing it back when you are through, but if your program crashes,
> then the user will have to change it back manually.
>
> Generally speaking, it is bad form to change any of the user's desktop
> settings.

I can not see any need to change it either.

But the original poster must have had some idea with it.

Arne


Scott M.

unread,
Feb 12, 2010, 10:16:05 AM2/12/10
to

"Arne Vajh�j" <ar...@vajhoej.dk> wrote in message
news:4b74bd69$0$273$1472...@news.sunsite.dk...

It may be for something like a video game, where there is an "Options"
section that allows the user to change resolution for the duration of the
game. It could be that the resolution change is actually initiated by the
user of the program and then the program returns the resolution back to its
original state when the program exits.

You are both right that this shouldn't be done without the user's consent,
but there may well be perfectly acceptable reasons to do it with the user's
concent.

-Scott


0 new messages