How to change form size as screen dimentions chaged?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dipalipatel
    New Member
    • Nov 2008
    • 21

    How to change form size as screen dimentions chaged?

    Hi,

    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??
  • admehta28
    New Member
    • Dec 2008
    • 2

    #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

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      I think admehta28 is refering to this:
      this.AutoScaleM ode = AutoScaleMode.D pi
      //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?

      Comment

      • dipalipatel
        New Member
        • Nov 2008
        • 21

        #4
        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:
        [code=c#]

        public static void ScaleDown(Syste m.Windows.Forms .Form frm)
        {
        int scrWidth = System.Windows. Forms.Screen.Pr imaryScreen.Wor kingArea.Width;
        int scrHeight = System.Windows. Forms.Screen.Pr imaryScreen.Wor kingArea.Height ;
        if (scrWidth < frm.Width)
        {
        foreach (System.Windows .Forms.Control cntrl in frm.Controls)
        {
        cntrl.Width = ((cntrl.Width) * (scrWidth)) / (frm.Width);
        cntrl.Left = ((cntrl.Left) * (scrWidth)) / (frm.Width);
        }
        }

        if (scrHeight < frm.Height)
        {
        foreach (System.Windows .Forms.Control cntrl in frm.Controls)
        {
        cntrl.Height = ((cntrl.Height) * (scrHeight)) / (frm.Height);
        cntrl.Top = ((cntrl.Top) * (scrHeight)) / (frm.Height);
        }
        }
        }

        [/code]
        But still some of the controls and form is not properly display


        Any idea ??

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          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..

          Comment

          Working...