change screen resolution in C#

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; 

} 

0
Utf
2/9/2010 11:39:09 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

6 Replies
1321 Views

Similar Articles

[PageSpeed] 25

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@discussions.microsoft.com> wrote in message 
news:6F9C4CED-AF25-44D2-B76B-548C00B5AE0A@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;
>
> }
> 


0
Scott
2/9/2010 11:47:59 PM
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
0
UTF
2/10/2010 1:18:32 AM
"Ed Hochberg" <EdHochberg@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. :-) 


0
Michael
2/10/2010 4:16:42 AM
On Feb 9, 5:39 pm, Ed Hochberg <EdHochb...@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.
0
Chris
2/11/2010 8:11:39 PM
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


0
ISO
2/12/2010 2:31:13 AM
"Arne Vajh�j" <arne@vajhoej.dk> wrote in message 
news:4b74bd69$0$273$14726298@news.sunsite.dk...
> 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

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
Scott
2/12/2010 3:16:05 PM
Reply:

Similar Artilces:

External data link change
Hi, I've a sheet linked to an external data on the net, and I would like that a cell in this sheet to indicate the last date and time it was updated, the simplest way the better but I can do some programming too. Thanks for your attention, -- Domingos Junqueira No need of help any more, I solved the question. Thanks again ...

Increase the resolution of a picture in a pdf/ publisher document
I created an ad in publisher, which included our logo, converted it to a PDF document and submitted it to the company. They informed me that the logo was not the same "high resolution" and would not print as clearly as the rest of the document. How do I fix the resolution of the logo. I have a copy of the logo in Microsoft Picture Manager also. Please help I am new at this. Thanks You can't increase the resolution and not end up with crap. (I couldn't find a nicer word, sorry.) The part that doesn't make sense is that the entire ad is the same resolution in the ...

Why does the change change to a number?
Hi all, I've noticed something wierd and always wondered WHY it happens. When you type a date into a cell, and then change the Formatting of it to a 'general' cell, it turns into a number. How does it come up with that number? What is the significance? i.e. type today's date of "12/7/2007" - change it to a 'General' format, and it then says "39423". I'm a trainer of Excel and this question always comes up. I'm curious myself too. Thanks! Joe It's the number of days since January zero 1900 using Excel default for windows (M...

DST changes for Exchange 5.5
I noticed the 2007 DST Calendar Update "Exchange tool" is available now: http://support.microsoft.com/kb/930879 This will seemingly take care of calendars for mailboxes still on Exchange 5.5 servers, as Exchange 5.5 is listed as "compatible" . However would this address the CDO issues such as BlackBerry users and OWA users still on Exchange 5.5 ? Thanks in advance, Itrcb4 On Mon, 12 Feb 2007 14:31:00 -0800, itrcb4 <itrcb4@discussions.microsoft.com> wrote: >I noticed the 2007 DST Calendar Update "Exchange tool" is available now: > >http://su...

Track Changes
How do i remove the track changes in outlook? When i press "Enter", a symbol that represents "Enter" will appears. Same for space etc. ...

Position of New Excel Spreadsheet on screen
I have a number of password protected workbooks. The problem is, when I open one, it opens behind any currently on screen, so I have to close/minimise them to display the window where I input the password. Is there a setting where I can make sure all new workbooks open on top of those already open? I'm using W7 and Office 2007 ...

changing the way Excel displays selected cells
Is there a way to change the way Excel displays selected cells? I'm interested in viewing all the selected cells highlighted (with light blue for instance), but by default excel highlights all the cells but not the first one the same occurs when you define a range with no adyacents cells Your definition of the display is not quite correct. Excel highlights the current cell, Excel also highlights a selecte range. The currently selected cell is generally the first of a range, bu press enter and the current cell changes and becomes the second, the third etc in the range. You cannot...

more on VBA function name change
I thought I'd start a new thread since I haven't received any replies to my first one... To recap: I've declared a function in a module using mixed case: Function TMDE_Category (FormName As Form) I noticed recently that it appeared in the module as Function tmde_category(FormName As Form) I changed it back to the mixed case declaration, saved the module, exited the app, reopened it and looked. The function had changed back to the all lowercase declaration. Things I've tried since the original post: Using the databse documenter, I selected all ob...

Can't Publish changes with Deploy Manager
After a migration process, I can't publish the changes made on CRM. When I try do this in Deploy Manager I get the follow error: ---------------------------------------------------------------------------- ----- Publish done with errors. See the event log to get deitails NETRA-INOVACAO: ***Error*** Failed to download XSL template files from Web Server ---------------------------------------------------------------------------- ----- Can somebody help me? I don't know if the migration process have any relationship with the error. Thank you for pay attention. []'s Vin�cius Pitta...

How to change icon for my application
Hi, I am currently developing an application on visual studio 6.0, and i wish to change the MFC icon on my application header. Anyone can help? Thank you. Raed Sawalha wrote: > Hi, I am currently developing an application on visual studio 6.0, and i > wish to change the MFC icon on my application header. Anyone can help? Thank > you. > > Open the icon resource for editing by double clicking. Then notice the control just above the editing grid that lets you switch between editing the large icon and editing the small one. -- Scott McPhillips [VC++ MVP] thanx that work...

Excel Pivot Items Using C#
I am working on a C# add-in that modifies pivot tables. I have done this work in VBA, and the object model seems straightforward, e.g., PivotTable-PivotFields-PivotItems, but I can not get the object for PivotItems, or iterate through the items. Do I need something other than PivotItems? Code for PivotFields, that works: IExcel.PivotFields pvtfs = (IExcel.PivotFields) pvtTable.get_PageFields(Missing.Value); foreach (IExcel.PivotField pvtf in pvtfs) { Code for the does nto work, and PivotItems shows no va...

How to change newsgroup message font
Like many other ribbon based programs I sometimes struggle to find how to make a change. This time its how to change the font just for newsgroup messages? regards "nobody" wrote in message news:EWTao.39493$GF5.7129@hurricane... > Like many other ribbon based programs I sometimes struggle to find how to make a change. This time its how to change the font just for newsgroup messages? Newsgroup messages are usually plain text. The font used is that selected at [no name tab] > Options > Mail > Read > Fonts for the encoding specified for the messag...

translate dll/tlb (for Excel as client) from VB.net to C#
I created a library control in VB.Net some time ago for implementing some .Net functionality for Excel as the client -- and made it com visible. I want to redo this in C#. Additionally, I want to be able to pass data to this control from Excel VBA. And lastly, I need to display some results in a gui thing like a label or - ideally - just the user control form The following is the Interface part of my dll/tlb (I left out the guts of the procedures). What is the C# syntax of this? Only need enough to get me started Imports System.Runtime.InteropServices Imports System.Data....

Notify change of email address when changing ISP
How do I notify my entire address book of an email address when I change ISP's? Thanks By sending a mail to everyone ? If you do so, please use BCC for the adresses, this way you won't spread everybody's e-mail adres to everybody. Niels Bob Baker wrote: > How do I notify my entire address book of an email address when I change ISP's? > Thanks ...

Change a formula to an acual number
I want to change the formula I have created to the number it has created Example: Cell A1 is the number 1. Cell A2 is the formula =a1+1 creatin the number 2. I want this to be a two not a formula. Any ideas? Laura, copy, then paste special, valves -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2000 & 97 ** remove news from my email address to reply by email ** "Laura" <anonymous@discussions.microsoft.com> wrote in message news...

Compatibility wiith Kkonica C-350
Using Windows XP with Publisher 2003. We publish a monthly newsletter on 11 by 17 format. We recently leased a new Konica C-350 and can not learn the interface for printing the newsletter directly to the Konica. We've tried almost everything and decided to tape the 8 1/2 by 11 pages together to copy them in the right format. A decidedly low tech approach to a simple matter. If anyone kknows how to do this "big" problem, please let me know. I'll want to try your suggestions. Is both your newsletter and your printer setting set for that size paper? Have you looke...

Problem Changing an Investment Name
I am trying to change an investment name and Money 2006 tells me "The name or symbol 'TRP Spectrum Income' has already been used for a deleted investment. Please enter a different name." When I go to delete investments the name does not appear! Any ideas on how I get Money to accept the name change? This is the first time I have run into this situation and I have made numerous name changes in Money over the years. In microsoft.public.money, Ken wrote: >I am trying to change an investment name and Money 2006 tells me "The name >or symbol 'TRP Spec...

Should I change this code?
Should I change 556 to 560???..............Thanks for your help..........Bob Private Sub Command560_Click() On Error GoTo Err_Command556_Click Dim stDocName As String Dim stLinkCriteria As String stDocName = "frmClientInfomation" DoCmd.OpenForm stDocName, , , stLinkCriteria Exit_Command556_Click: Exit Sub Err_Command556_Click: MsgBox Err.Description Resume Exit_Command556_Click End Sub On Sun, 15 Jul 2007 16:37:26 +1200, "Bob V" <rjvance@ihug.co.nz> wrote: > >Should I change 556 to 560???..............Thanks for your help.....

How to change default font in Outlook 2003
Can someone tell me how to change tthe default font in Outlook 2003 when composing a new email. It always comes up as Times New Roman. I remember somewhere that I specified that Outlook should use Word as the text editor and that seems to be the case. I have Arial as my default font in Word but this seems to make no difference when using Outlook. Hi, Please go to Tools > Setting > Mail Format > Stationery and Fonts > Fonts It's right there :) On 20 Nov 2005 06:28:45 -0800, amarsarit@gmail.com wrote: >Hi, >Please go to Tools > Setting > Mail Format > Statione...

icon changes with change of extension
when we change the extension of a file in windows, its icon also changes..... how does windows do tht. in my application i require a similar approach. i want the icon to be dependent on the file extension not on the attributes of the file. i have gone trough the registry but things are not very clear. Windows has listed all the file extensions avaliable there, but there is no general way to extract icons for those extension... kindly help icon changes with change of extension "Neelu" <nemesia31@gmail.com> wrote in message news:1161232739.720722.120950@b28g2000cwb.google...

Field Type Change
I am trying to change a free text field to a drop down menu in my current database, that already has data entered for this particular field, in order to avoid multiple versions of the same organization that are just typed in differently. I'm assuming that I'll need to recode the different versions of an entry to make them uniform but after that, I'm unsure how to proceed so I won't lose any data. Is this possible or will I need to delete the field, recreate it as a drop down and then re-enter the data? Thanks in advance! Mike Thanks everyone for all the input and advice s...

Tracking Changes
I am the author of a document and am making revisions to it. I want to chnage the redline color to denote new edits from the 1st version. Can anyone guide me through this process? I am sure it is easy but I cannot figure it out. THanks Peter On Wed, 10 Feb 2010 07:08:06 -0800, Peter SSI <Peter SSI@discussions.microsoft.com> wrote: >I am the author of a document and am making revisions to it. I want to >chnage the redline color to denote new edits from the 1st version. Can >anyone guide me through this process? I am sure it is easy but I cannot >figure i...

Save Changes? #2
Sometimes, but not always, Excel asks if I want to save the current file, even though I've made no changes. Does anyone know why this occurs, and if there is a setting I can change to avoid the prompt unless actual changes are made? Thank you. Sprinks There are a number of functions that will update themselves when the workbook is opened, and this causes Excel to act as though the workbook has been changed. These functions include NOW() , TODAY(), ROW(), etc. See Volatile Functions in help for more info. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consult...

colour change of dated box
How can I change the colour of a dated box of excel after the date is over. I want the programme to read date automatically from pc and change colour. try Conditional Formatting In 2003: 1. Select the cells you want to format 2. Choose Format, Conditional Formatting 3. Choose Cell Value Is from the first drop down 3. Choose Formula is from the first drop down 4. Choose less than 5. In the third box, enter =TODAY() 6. Click the Format button 7. Choose a color on the Patterns tab (or any available option) 7. Click OK twice. -- Hope this is helpful Appreciate that you provide your feedbac...

Daylight saving time changes for Exchange 2003 server
Hi guys, I was wondering how other real life systems administrators are preparing for the upcoming “2007 global time zone update for Windows” (daylight time change for exchange 2003 server). I'd like to know what contingency plans are being planned out to implement this update and what practical ideas you think thus far are the best. I would greatly value your input. http://www.microsoft.com/windows/timezone/dst2007.mspx -Thanks! ...