By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 1,592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

How to change form size as screen dimentions chaged?

P: 21

I have one c# smart device application created in .net 2005. I have fixed size form for my one device.

Now i have another device and screen size is chaged menas it is more wider and short in size.
If i run same application then some of the controls are not visible as screen dimentions chages.

So, is there any way i can auto size my forms as per screen dimentions.

For exmple if i have screen dimensions like 251 X 300 it works fine
but if i have 300 X 340 it wont display my controls properly.

So, is there any method that automatically adjust my controls as screen dimensions chages.

Please, Can any one help me with this??
Dec 19 '08 #1
Share this Question
Share on Google+
4 Replies

P: 2
Hello, I think you are talking about Window Base Application so in that matter you should set the AutoScale Property of Window Form. By Default It is Font but you can set as dpi. I think this will help you

Good Luck
Dec 19 '08 #2

Expert 5K+
P: 7,872
I think admehta28 is refering to this:
this.AutoScaleMode = AutoScaleMode.Dpi
//this is the Form object you wish to change.

I don't know how to use it, or if its available to you on smart device applications.

You could consinder on startup of that form, checking what the size of the screen is, and making your adjustments mathmatically?
Dec 19 '08 #3

P: 21
Hi Plater,

Actullay admehta28 is right Autoscale property is availble in framework 2.0 not in 1.0 and yes it is windows applicaiton.

I am using 1.0 framwork so i donot have that property.
So, basically what i was doing is calulating working area and my form size mathamatically, but i am not sure exectly how my all controls get adjust so that is why i put this questions.
for future details i can give u an example what i did.

Below my sample method:
Expand|Select|Wrap|Line Numbers
  2. public static void ScaleDown(System.Windows.Forms.Form frm)
  3. {
  4.   int scrWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
  5.   int scrHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
  6.   if (scrWidth < frm.Width)
  7.   {
  8.         foreach (System.Windows.Forms.Control cntrl in frm.Controls)
  9.         {
  10.             cntrl.Width = ((cntrl.Width) * (scrWidth)) / (frm.Width);
  11.             cntrl.Left = ((cntrl.Left) * (scrWidth)) / (frm.Width);
  12.         }
  13.   }
  15.   if (scrHeight < frm.Height)
  16.   {
  17.         foreach (System.Windows.Forms.Control cntrl in frm.Controls)
  18.         {
  19.             cntrl.Height = ((cntrl.Height) * (scrHeight)) / (frm.Height);
  20.             cntrl.Top = ((cntrl.Top) * (scrHeight)) / (frm.Height);
  21.         }
  22.     }
  23. }
But still some of the controls and form is not properly display

Any idea ??
Dec 19 '08 #4

Expert 5K+
P: 7,872
Are any of your controls inside a "container" control, like a GroupBox or a Panel (or etc)?
Becase they would not get resized in the function you provided. You need to check to see if any of the controls also have controls
The function you have is the right idea I think though..
Dec 19 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.