diff options
author | Karl <5079870+PreferLinux@users.noreply.github.com> | 2020-01-13 19:15:09 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2020-01-13 19:15:09 +0300 |
commit | 8bd438f318b6bafdd610ca94760c7f70097b6a31 (patch) | |
tree | 0448a458417c66698e52935deefe854707f6ef99 /mcs | |
parent | 4ee4d368c649e024b516cb26245d9bdd14baa1df (diff) |
[Winforms] Calculate GroupBox preferred size the same way as Panel (#18429)
GroupBox's GetPreferredSize() is not great. I've simply copied the code from Panel, and used that. It uses LayoutEngine.GetPreferredSize(), which does things a lot better than the code this used.
Diffstat (limited to 'mcs')
-rw-r--r-- | mcs/class/System.Windows.Forms/System.Windows.Forms/GroupBox.cs | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/mcs/class/System.Windows.Forms/System.Windows.Forms/GroupBox.cs b/mcs/class/System.Windows.Forms/System.Windows.Forms/GroupBox.cs index c047a77ebfe..02bbd3ca9ec 100644 --- a/mcs/class/System.Windows.Forms/System.Windows.Forms/GroupBox.cs +++ b/mcs/class/System.Windows.Forms/System.Windows.Forms/GroupBox.cs @@ -307,28 +307,12 @@ namespace System.Windows.Forms #region Internal Methods internal override Size GetPreferredSizeCore (Size proposedSize) { - Size retsize = new Size (Padding.Left, Padding.Top); - - foreach (Control child in Controls) { - if (child.Dock == DockStyle.Fill) { - if (child.Bounds.Right > retsize.Width) - retsize.Width = child.Bounds.Right; - } else if (child.Dock != DockStyle.Top && child.Dock != DockStyle.Bottom && (child.Bounds.Right + child.Margin.Right) > retsize.Width) - retsize.Width = child.Bounds.Right + child.Margin.Right; - - if (child.Dock == DockStyle.Fill) { - if (child.Bounds.Bottom > retsize.Height) - retsize.Height = child.Bounds.Bottom; - } else if (child.Dock != DockStyle.Left && child.Dock != DockStyle.Right && (child.Bounds.Bottom + child.Margin.Bottom) > retsize.Height) - retsize.Height = child.Bounds.Bottom + child.Margin.Bottom; - } - - retsize.Width += Padding.Right; - retsize.Height += Padding.Bottom; - - retsize.Height += this.Font.Height; - - return retsize; + // (Copied from Panel) + // Translating 0, 0 from ClientSize to actual Size tells us how much space + // is required for the borders. + Size borderSize = SizeFromClientSize(Size.Empty); + Size totalPadding = borderSize + Padding.Size; + return LayoutEngine.GetPreferredSize(this, proposedSize - totalPadding) + totalPadding; } #endregion |