2

I have panel control. More controls are in panel.I set the dock property for panel as 'fill' .The panel are resized based on screen resolution. but the controls remains same.The controls in the panel are not resized based on screen solution.

i have more labels and panels and text-boxs and button in the same page.

How to set the dock property to resize all controls in page based on screen resolution?

Thanks for any help

skaffman
  • 398,947
  • 96
  • 818
  • 769
user337173
  • 21
  • 1
  • 2
  • 1
    Dock and Anchor properties are for "layout" only. AutoScaleMode and AutoScaleDimensions properties are for "screen-resolution" changes. – AMissico May 10 '10 at 13:25

3 Answers3

1

I hope this solution (drawn from here) will help display all the controls inside the form when the screen resolution changes at the client side:

int i_StandardHeight = 768;//Developer Desktop Height Where the Form is Designed
                int i_StandardWidth = 1024; ;//Developer Desktop Width Where the Form is Designed
                int i_PresentHeight = Screen.PrimaryScreen.Bounds.Height;
                int i_PresentWidth = Screen.PrimaryScreen.Bounds.Width;
                float f_HeightRatio = new float();
                float f_WidthRatio = new float();
                f_HeightRatio = (float)((float)i_PresentHeight / (float)i_StandardHeight);
                f_WidthRatio = (float)((float)i_PresentWidth / (float)i_StandardWidth);
                foreach (Control c in this.Controls)
                {
                    if (c.GetType().ToString() == "System.Windows.Forms.Button")
                    {
                        Button obtn = (Button)c;
                        obtn.TextAlign = ContentAlignment.MiddleCenter;
                    }
                    if (c.HasChildren)
                    {
                        foreach (Control cChildren in c.Controls)
                        {
                            cChildren.SetBounds(Convert.ToInt32(cChildren.Bounds.X * f_WidthRatio), Convert.ToInt32(cChildren.Bounds.Y * f_WidthRatio), Convert.ToInt32(cChildren.Bounds.Width * f_WidthRatio), Convert.ToInt32(cChildren.Bounds.Height * f_HeightRatio));
                            //cChildren.Font = new Font(cChildren.Font.FontFamily, cChildren.Font.Size * f_HeightRatio, cChildren.Font.Style, cChildren.Font.Unit, ((byte)(0)));
                        }
                        c.SetBounds(Convert.ToInt32(c.Bounds.X * f_WidthRatio), Convert.ToInt32(c.Bounds.Y * f_WidthRatio), Convert.ToInt32(c.Bounds.Width * f_WidthRatio), Convert.ToInt32(c.Bounds.Height * f_HeightRatio));
                       // c.Font = new Font(c.Font.FontFamily, c.Font.Size * f_HeightRatio, c.Font.Style, c.Font.Unit, ((byte)(0)));
                    }
                    else
                    {
                        c.SetBounds(Convert.ToInt32(c.Bounds.X * f_WidthRatio), Convert.ToInt32(c.Bounds.Y * f_WidthRatio), Convert.ToInt32(c.Bounds.Width * f_WidthRatio), Convert.ToInt32(c.Bounds.Height * f_HeightRatio));
                       // c.Font = new Font(c.Font.FontFamily, c.Font.Size * f_HeightRatio, c.Font.Style, c.Font.Unit, ((byte)(0)));
                    }
                }
                this.Height = Convert.ToInt32(i_StandardHeight * f_HeightRatio);
                this.Width = Convert.ToInt32(i_StandardWidth * f_WidthRatio); 
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
IMMORTAL
  • 2,707
  • 3
  • 21
  • 37
1

Use the Anchor property and anchor the control to all 4 sides.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
0

In addition to setting the Dock property of the container Panel, you also have to set the Anchor or Dock properties of controls within the Panel. Usually, adding a TableLayoutPanel, FlowLayoutPanel, or even another Panel will help when you have multiple controls on a Form.

AMissico
  • 21,470
  • 7
  • 78
  • 106