AutoScaling .NET 2.0

In my current Application I have to max  the Windlows Client width and height to the Monitor Size.
If the monitor resolution changes it should scale to the new width and height.
Also the controls within the forms should scale and position automatically.

I have default client size set to 800 * 640 . So when the app loads if the client size is different than
the Monitor Resolution I calcuate the Width Height and Location for each control a

Eg. The function below calcuates the width of control with respectto the Monitor size.
Here width parameter is the actual control width when the size is 800.
 public static int SetWidth(int width)
             decimal scale = Math.Round(((decimal)width/(decimal)800), 4);
            return Convert.ToInt32(System.Windows.Forms.SystemInformation.PrimaryMonitorSize.Width * scale);

Is there any other default way in .NET to do  auto scaling of forms & controls.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi AdibRahman77;

What you are talking about is call resolution independence and Microsoft does not support this although I understand that Windows Vista was to support it but do not know if it does.

There are products that give true resolution independence and here are a couple.

For example the produce from Soft-Group Components state the following:

· Gives your Windows Forms applications resolution independence.
· Keep your controls font/size proportion whenever your forms are resized
· Can be easily implemented to already designed forms with 1 line of code
· Support controls nested inside others
· Can centerl form over the Desktop or MDI Parent
· Can save/resotre your form's last size and positions.
· Resizes fonts as well as the controls themselves
· Ability to specify whether the fonts of the controls will be resized or not.
· Control resize of docked controls like ToolStrip and StatusStrip.
· Support of standard .Net Windows Form, MDI child and MDI parent Forms.
· Fast, small and accurate resize engine.

Soft-Group's web site. "You can download a 30 day trial version" of Softgroup .Net Forms Resize

Another such product is Xsize from HALLoGRAM Publishing

If you Google the phrase "Resolution Independence" you will find others.

My above statements does not in any way support any of these product.

AdibRahman77Author Commented:
There is no solution put on. I cannot use third party product.
Fernando SotoRetiredCommented:
Go to the below link for Soft-Group's web site. "You can download a 30 day trial version" of Softgroup .Net Forms Resize
And follow the link on the page for "Softgroup .Net Forms Resize"  <<<

The other link seems to no longer be valid since I posted it on 2/08/2008

AdibRahman77Author Commented:
I cannot use third party product. Looking for some ideas on manual scaling
AdibRahman77Author Commented:
I did manual scaling by applying some mathematical logic

It sets size font and location for each control .. attached code
 public static Size GetSize(int width, int height)
            decimal xscale = Math.Round(((decimal)width / (decimal)800), 4);
            decimal yscale = Math.Round((decimal)height / (decimal)610, 4);
            return new Size(Convert.ToInt32(monSize.Width * xscale), Convert.ToInt32(monSize.Height * yscale));
 public static Font GetFont(float size, FontStyle fstyle)
            decimal fscale = Math.Round(((decimal)size / (decimal)800), 4);
            return new System.Drawing.Font("Arial", (float)Math.Round(((decimal)monSize.Width * (decimal)fscale), 4), fstyle, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        public static Point GetLocation(int X, int Y)
            decimal xscale = Math.Round(((decimal)X / (decimal)800), 4);
            decimal yscale = Math.Round((decimal)Y / (decimal)610, 4);
            return new Point(Convert.ToInt32(monSize.Width * xscale), Convert.ToInt32(monSize.Height * yscale));

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.