2010-05-10 138 views
2

我有面板控制。更多控件在面板中。我將面板的dock屬性設置爲「填充」。面板根據屏幕分辨率調整大小。但控件保持不變。面板中的控件不會根據屏幕解決方案調整大小。基於屏幕分辨率控制調整大小

我在同一頁面有更多的標籤和麪板以及文本框和按鈕。

如何設置dock屬性來根據屏幕分辨率調整頁面中的所有控件?

感謝所有幫助

+1

碼頭和錨性質是「佈局」而已。 AutoScaleMode和AutoScaleDimensions屬性用於「屏幕分辨率」更改。 – AMissico 2010-05-10 13:25:10

回答

1

使用Anchor財產和錨控制所有4個方面。

0

除了設置容器面板的Dock屬性之外,還必須在Panel中設置控件的Anchor或Dock屬性。通常情況下,添加TableLayoutPanel,FlowLayoutPanel或甚至另一個面板將有助於在窗體上有多個控件時。

1

我希望這個解決方案(從here畫)將有助於顯示錶單中的所有控件,在客戶端的屏幕分辨率更改:

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); 
+0

謝謝它的工作 – 2013-02-18 10:07:50