Click to See Complete Forum and Search --> : Screen Resolution!!


rocky_upadhaya
January 29th, 2010, 11:14 PM
Hello....Please Evaluate and help me on this problem.....Here I have a simple form with background Picture and 4 buttonsThe Problem is that I have created this Sample Apps in the screen resolution of 1024 X 768.....so when I change my screen resolution to 800 X 600 Other 3 buttons gets hidden...and If I change my screen Resolution to more than 1024 X 768 say 1280 X 1024 then the Space between buttons and Screen Extrimities on the Right and down Increases......Please Hemp me on this Apps so that It works fine on most of the desktop screen resolutions.....

rocky_upadhaya
February 1st, 2010, 08:33 AM
Since This Problem seems impossible or very hard for my level of knowledge till now and no one is willing to help me on this problem I am very frustated......So Please Suggest me code to change the screen resolution....I have found some code in the internet but was unable to use them cause I didnt knew exact namespace....or something else.......Please help me out here

string Htscreen = SystemInformation.PrimaryMonitorSize .Height .ToString();
string WtScreen=SystemInformation.PrimaryMonitorSize.Width .ToString();

I want to keep HtScreen and WtScreen values to change the screen resolution to original state if I exit from the application Bu please Help me on the code for changing screen resolution....

nelo
February 1st, 2010, 09:08 AM
Since This Problem seems impossible or very hard for my level of knowledge till now and no one is willing to help me on this problem I am very frustated.I don't think it is fair to say that no one is willing to help you. I've noticed that you have another post on the subject and you had a lot of replies there. If the problem is not solved yet you have to be more patient. It is probably a difficult think to do. Otherwise Google would have solved it for you. Also try other forums. Secondly frustration will not help. The help you get is voluntary, it is not owed. If you get any be grateful. Thirdly why do you want to change the resolution if you don't mind me asking?

rocky_upadhaya
February 1st, 2010, 09:26 AM
Sorry for using "not Willing" term...that was all my bad....I want to change the screen resolution because few weeks back I Took my csharp application to my friend's computer...but his default screen resolution was in 800 X 600 so It didnt looked nice plus many of my buttons got hidden..........

nelo
February 1st, 2010, 09:33 AM
So you want your application to change the resolution on the machine it is running on? I'm sure that is possible but a better way to address the real problem is to re-design the screen. Fight the battles worth fighting for...:)

rocky_upadhaya
February 1st, 2010, 10:32 AM
No I Just Wanted to mimic it from simple games.....like some game like counter strike etc.... Works fine in almost all resolution because they change the system screen resolution to their resolution during gameplay only.....Since I my current knowledge was not good enough for my application to run fine on atleast 3-4 default monitor resolution...I have presented this question infront of you guys if someone has any idea??

mariocatch
February 1st, 2010, 10:55 AM
I've never tried changing the resolution before, but I just did a google search for "C# change resolution" and there are tons of examples.

rocky_upadhaya
February 1st, 2010, 11:53 AM
Common Let's not give such a answer.....Everyone knows how to use Bing or Google...Tried few of them with no success...The Most promising was..

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

I dont only put question and relax....Yes I do keep question in Here more than others do..but I also do my homework(research) parallely too.....I just put because if someone already knows the solution to the question it would be easier for me and other guys who may have the similar problem......sometimes I can be little unreasonable too....so sorry 4 that in advance.....but in the code above it says "The type or namespace name 'Resolution' could not be found (are you missing a using directive or an assembly reference?)......does anyone has any idea on what using statement is required??

nelo
February 1st, 2010, 12:10 PM
sometimes I can be little unreasonable too....so sorry 4 that in advance.....but in the code above it says "The type or namespace name 'Resolution' could not be found (are you missing a using directive or an assembly reference?)......does anyone has any idea on what using statement is required??

You probably need to download the source for that code snippet you got from your research. From my quick research the class 'CResolution' is in the 'Resolution' namespace. They are not a part of the .NET Framework. Download the source and integrate it into your application (You can do that here (http://www.csharphelp.com/2007/09/how-to-change-the-screen-resolution-in-c/)). I still think you are putting a lot of effort for very little benefit. Why not re-design the UI to fit the smallest possible resolution you intend to support?

mariocatch
February 1st, 2010, 12:10 PM
You can right click on the keyword (Resolution) and go to Resolve and choose the include namespace option.

Edit: If the namespace exists in your project references that is...

rocky_upadhaya
February 1st, 2010, 12:27 PM
nelo....has a point but.....I will re adjust my UI to make it make it run in any screen resolution.....but It would be helpful for future too...any ways thanks guys.......I have now downloaded .cs file which has Resolution namespace and a class called CResolution...I have never used csharp file templete written by other and use it in my code may I Expect a help from you guys??

Arjay
February 1st, 2010, 01:01 PM
Rocky, I didn't reply to this thread because I thought you had solved the issue of resizing your app in reponse to a resize notification (sent to your app when the user changes the resolution). I figured if you were able to do that, then it would be a simple matter for you to resize your app on startup (if you were able to do it dynamically in the other post).

What I didn't understand is that you wanted to force a resolution change.

Now that I understand what you are looking for, the best is I can say is don't do that. The vast majority of users don't want some application screwing with their user settings - changing resolution is a big no, no. Plus, you may not be able to pull it off anyway because the user may not have permissions to change the resolution. What are you going to do then? Fail? The professional way to deal with this is to make your app work under any resolution. Or at least reasonable resolutions - I wouldn't bother supporting 640 x 480 or 800 x 600.

As far as getting google answers. Understand that your google may not be as powerful as other's google (like 2nd or 3rd degree black belt google). So don't be upset if someone gives you google search terms because the terms they give you may be the actual terms you need to find the answer (even though you've already search with weak google). Remember our goal as the Code Guru collective is to be able to say at one point, "the google is strong in that one".

So young jedi, be sure that you are patient and listen to the responses you get here and actually put the advice into practice.

rocky_upadhaya
February 1st, 2010, 06:56 PM
Oh! I got the point....But do you have idea behind games like Mario,sonic and Counterstrike run on almost all screen resolution?? I just want to understand the idea now and if possible implement it.....otherwise I am now totally satisfied with answers of Arjay, nelo and MarioCatch....

BigEd781
February 1st, 2010, 07:09 PM
Well, I think you are talking about two different things. The actual screen resolution is set by the user, your game will adapt to that and scale appropriately to fit either in windowed or full screen mode. The ability to display in full screen is independent from the current resolution setting.

Arjay
February 1st, 2010, 07:13 PM
Oh! I got the point....But do you have idea behind games like Mario,sonic and Counterstrike run on almost all screen resolution?? I just want to understand the idea now and if possible implement it.....otherwise I am now totally satisfied with answers of Arjay, nelo and MarioCatch....Yes. They detect the current screen resolution and adjust their sizing as appropriate. Build yourself a simple form app that is resizable (when the user drags the lower, right corner of the form). Next, makes the controls in the form resizable. After that detect screen changes (like you did in the other app). Finally make the form resize itself on startup. Once you all that, then that's all you need to know with regard to resolution. If you need to know how to set the resolution, by the time you have worked through the previous items, you'll know how to do it.

rocky_upadhaya
February 2nd, 2010, 11:48 AM
OK! I am little confused between the terms "resizing" application and changing the resolution of screen....any way little hint or piece of code for me to work on please.....

mariocatch
February 2nd, 2010, 11:53 AM
Resizing the application means, you should redesign your UI to make it work on any reasonable resolution the display might happen to be in.

Changing the resolution of the screen means running your application in full screen mode or in windowed mode typically.

Arjay
February 2nd, 2010, 12:10 PM
Changing the resolution also means that you alter the user's display settings. For example, because your program can only handle 1024 x 768 resolution, the program programatically changes the system resolution to 1024 x 768.

As mentioned in a previous post, a well behaved program should not alter user display settings.

rocky_upadhaya
February 2nd, 2010, 12:16 PM
Yes Exactly! I thought it would be easier to change the resolution of computer until i got answer from you guys.......the programs I designed have picbox, buttons etc...If computer's resolution is not in exactly 1024 X 768 the whole orientation goes wrong...so what should i do to avoid this....

Arjay
February 2nd, 2010, 12:16 PM
I can't really stress the importance of leaving the user settings alone.

Imagine if I wrote a program that moved the taskbar to the left side of the screen, change the resolution to 640 x480 and minimized all open applications to the taskbar. Then after running for 5 minutes, I closed all other running programs.

Do you think users would like this app?

Proper app design means that your app runs in the environment is it given and doesn't alter that environment.

mariocatch
February 2nd, 2010, 12:22 PM
Although WPF applications are a lot easier to scale to window sizes/resolutions, you can still do the same in WinForm.

I suggest taking a look at the Docking patterns that WinForm (and WPF) provides. With docking, you can essentially force UI elements to alway stay a certain distance away from edges of other UI elements, or borders of the window. This will allow the UI to scale as the size changes.

Arjay
February 2nd, 2010, 01:07 PM
Yes Exactly! I thought it would be easier to change the resolution of computer until i got answer from you guys.......the programs I designed have picbox, buttons etc...If computer's resolution is not in exactly 1024 X 768 the whole orientation goes wrong...so what should i do to avoid this....As explained earlier, you need to respond to resize events and resize the controls. See the attached app and look at the Anchor styles for each control. Between this style and an the Dock style mentioned by Mario, you can get the controls on the form to auto-resize. The first step is to get the form to resize it's controls when the user changes the size of the form (by dragging the resize chevron in the lower right corner of the form).

See the attached project for a basic form that resizes the controls when the user changes the form size.

Once you get that down, then the next step is to respond to an DisplaySettings change event (as already outlined in the other post) and programmatically set the form size. If you've done the resizing work here (as shown by the attached project), then the controls will resize when you set the form size.

nelo
February 3rd, 2010, 04:44 AM
Yes Exactly! I thought it would be easier to change the resolution of computer until i got answer from you guys.......the programs I designed have picbox, buttons etc...If computer's resolution is not in exactly 1024 X 768 the whole orientation goes wrong...so what should i do to avoid this....

Here's my advice. Give the picture box fixed dimensions and do the same for the buttons. Change your screen resolution to the minimum resolution you intend to support. Try the application in that resolution and make any adjustments necessary. I've not seen anything in your requirements that indicates the screen has to scale up or down depending on the resolution. You should be able to disable the 'Maximise' button so that your form always has the size (i.e. just big enough to fit all the controls inside it. That way it will look the same in all the resolutions you want to support. Of course under higher higher resolutions your form will take up less space...

rocky_upadhaya
February 3rd, 2010, 04:52 AM
Superb!! Exactly what I wanted....Thanks......

pweegar
February 3rd, 2010, 04:24 PM
See if any of this is helpful:
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/3fac4578-53ff-4994-a08e-85e7df854e99

and also:
http://msdn.microsoft.com/en-us/library/system.windows.forms.screen.aspx

rocky_upadhaya
February 5th, 2010, 09:29 AM
Suppose I have lots of adjecent rtfboxes side by side(say 20)....So only the rightmost rtf box is stretched......is there any way to make this streching or resizing rationally?? ie every rtf boxes should strech equally......

Arjay
February 5th, 2010, 10:09 AM
Suppose I have lots of adjecent rtfboxes side by side(say 20)....So only the rightmost rtf box is stretched......is there any way to make this streching or resizing rationally?? ie every rtf boxes should strech equally......You'll need to handle the onsize event of the form, get the width of the form and manually resize each of the text boxes.

rocky_upadhaya
February 5th, 2010, 10:27 AM
int HtScreen = SystemInformation.PrimaryMonitorSize.Height;
int WtScreen = SystemInformation.PrimaryMonitorSize.Width;

if (HtScreen < 1030 || HtScreen > 805 && WtScreen<770||WtScreen>595) // checks the screen resolution
{
this.ClientSize = new System.Drawing.Size(1024, 768); //resizes the size of screen
this.rtfBox1.Size = new System.Drawing.Size(80, 200); //resizes from 30,200->80,200
}


Is this code valid?? not workin with me....

rocky_upadhaya
February 5th, 2010, 10:56 AM
this.Resize += new System.EventHandler(this.ResizeMy_Resize);

//My Event Defintion
private void ResizeMy_Resize(object sender, System.EventArgs e)
{
int HtScreen = SystemInformation.PrimaryMonitorSize.Height;
int WtScreen = SystemInformation.PrimaryMonitorSize.Width;
//this.ClientSize = new System.Drawing.Size(WtScreen , HtScreen );
this.rtfBox1.Size = new System.Drawing.Size(80, 200);
}


Now that I have learned to resize my form according to the screen resolution(I think it is working....do I have to place anchoring code for buttons after resizing too??
secondly....this.rtfBox1.Size=new System.Drawing.Size(80,200) is not working..........

mariocatch
February 5th, 2010, 11:06 AM
Anchoring/Docking is a one time setup. Do it in your designer view or in the control setup code.

rocky_upadhaya
February 5th, 2010, 11:24 AM
yes I have anchored one button down but after resizing event is hit it moves way up the screen......I think the working area of my resized form is still 800 X 600 still after resizing it to 1024 X 768