From: Ed Hochberg on
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;

}

From: Scott M. on
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" <EdHochberg(a)discussions.microsoft.com> wrote in message
news:6F9C4CED-AF25-44D2-B76B-548C00B5AE0A(a)microsoft.com...
> 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;
>
> }
>


From: Arne Vajhøj on
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
From: Michael C on
"Ed Hochberg" <EdHochberg(a)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. :-)


From: Chris Dunaway on
On Feb 9, 5:39 pm, Ed Hochberg <EdHochb...(a)discussions.microsoft.com>
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.
>
> 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;
>
> }

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.