Click here to Skip to main content
Licence 
First Posted 4 Jan 2007
Views 17,242
Downloads 591
Bookmarked 10 times

Windows application that fits in all Resolutions

By | 4 Jan 2007 | Article
An article on Developing Windows application that Suits in all Resolutions.

Introduction

Designing Windows application that Fits in all resolutions will become necessary some times.Here i am explaining how you can do this.

Background

I have seen most of the applications that are designed in the previous time is of resolution 800 * 600 if you try to see that in resolution like 1200 * 800 it will not be that much clear and as the resolutions are increasing further it will become tough time for applications that are designed in lower resolutions.So i feel we Must develop our applications that can be well suited in all resolutions so that our client will not come with modification year to year as he is adopting all the technological changes.

Using the code

Here is how i Made my approach. First i started to get the Ratios of Designed Height to Current Height, and Designed Width to Current Width and using that ratios i am calculating the present height & width that must be in current resolution.But after that i came across Microsoft's AutoScale then i used that and it is working fine, But only one Problem is in Heigher Resolution i am not able to read the text on the form so i increased the font while setting the font family as the same.

I prefer to write the required form resizing code in another class and a method which contains all the required code. So that we can call that function in form load.I used this one in utility and called this because it will become large process if you want to modify this code as you need to modify in all forms. In my project i have 65 Windows Project modules so i used this as a Class.

Declare these Variables

float f_HeightRatio = new float();
float f_WidthRatio = new float();

ResizeForm(Form ObjForm, int DesignerHeight, int DesignerWidth)</code)

#region Code for Resizing and Font Change According to Resolution
//Specify Here the Resolution Y component in which this form is designed
//For Example if the Form is Designed at 800 * 600 Resolution then DesignerHeight=600
int i_StandardHeight = DesignerHeight;
//Specify Here the Resolution X component in which this form is designed
//For Example if the Form is Designed at 800 * 600 Resolution then DesignerWidth=800
int i_StandardWidth = DesignerWidth;
int i_PresentHeight = Screen.PrimaryScreen.Bounds.Height;//Present Resolution Height
int i_PresentWidth = Screen.PrimaryScreen.Bounds.Width;//Presnet Resolution Width
f_HeightRatio = (float)((float)i_PresentHeight / (float)i_StandardHeight);
f_WidthRatio = (float)((float)i_PresentWidth / (float)i_StandardWidth);
ObjForm.AutoScaleMode = AutoScaleMode.None;//Make the Autoscale Mode=None
ObjForm.Scale(new SizeF(f_WidthRatio, f_HeightRatio));
foreach (Control c in ObjForm.Controls)
{
    if (c.HasChildren)
    {
        ResizeControlStore(c);
    }
    else
    {
        c.Font = new Font(c.Font.FontFamily, c.Font.Size * f_HeightRatio,         c.Font.Style,     c.Font.Unit, ((byte)(0)));
    }
}
ObjForm.Font = new Font(ObjForm.Font.FontFamily, ObjForm.Font.Size * f_HeightRatio, ObjForm.Font.Style, ObjForm.Font.Unit, ((byte)(0)));
#endregion
ResizeControlStore(Control objCtl)
if (objCtl.HasChildren)
     {
        foreach (Control cChildren in objCtl.Controls)
        {
           if (cChildren.HasChildren)
           {
             ResizeControlStore(cChildren);
           }
           else
           {
             cChildren.Font = new Font(cChildren.Font.FontFamily, cChildren.Font.Size * f_HeightRatio, cChildren.Font.Style, cChildren.Font.Unit, ((byte)(0)));
           }
        }
                objCtl.Font = new Font(objCtl.Font.FontFamily, objCtl.Font.Size * f_HeightRatio, objCtl.Font.Style, objCtl.Font.Unit, ((byte)(0)));
      }
      else
      {
         objCtl.Font = new Font(objCtl.Font.FontFamily, objCtl.Font.Size * f_HeightRatio, objCtl.Font.Style, objCtl.Font.Unit, ((byte)(0)));
      }

How to use it in your application

  • Step 1:Take the code file that is included in the source and add that in any of your comman class library(ex:Utility)
  • Step 2:Add reference of the library to your project.
  • Step 3:In the Form_Load function Create Instance of the class.
  • Step 4:Call the Function ResizeForm by passing 3 Parameters(Form,DesignerHeight,DesignerWidth ex:objFormResizer(this,864,1152);

Points of Interest

Frankly speaking to complete this it is taken 3 days to me as the project that this is to be implemented consists of 60+ projects so i felt so sad and made my self to leave this task.(Previously Developers are designing the form in 3 to 4 common resolutions and in code they are putting these by copying from system default form generated code it is very large process and also if design changed and developer forgot to modify this then think of the form..) But due to this i came across so many design considerations in windows forms.

Thanks to all.

Developers and Senior Software people's suggestions are always accepted.I request the comments from all as this is my first posting.Please excuse me and come to me if any Mistakes are there.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

nagendra rao s.v.

Web Developer

India India

Member

Working as a Software Developer in Glow Touch Technologies in Mangalore,India.Experienced in VB,Windows Applications using .Net, ASP, ASP.NET.
Passionate of Learning New technologies.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberMember 39211791:47 29 Sep '10  
GeneralAlternate Approach PinmemberMember 32327662:02 1 Nov '08  
GeneralSample Files Not Found Pinmemberashish_mailbox2:05 29 May '07  
GeneralNot been reviewed Pinmemberspoodygoon7:14 21 Jan '07  
GeneralRe: Not been reviewed Pinmembernagendra rao s.v.2:14 29 May '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 5 Jan 2007
Article Copyright 2007 by nagendra rao s.v.
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid