Attached patch fixes bug #402849 and basically boils down to two main things

- We should check whether children are in AutoSize and only then ask
for PreferredSize, else use ExplicitBounds.
- Apply padding to the preferred size for Form.

If no objections, I will commit.

Thanks,
Ivan
Index: System.Windows.Forms/FlowLayoutPanel.cs
===================================================================
--- System.Windows.Forms/FlowLayoutPanel.cs	(revision 107002)
+++ System.Windows.Forms/FlowLayoutPanel.cs	(working copy)
@@ -120,7 +120,11 @@
 			bool horizontal = FlowDirection == FlowDirection.LeftToRight || FlowDirection == FlowDirection.RightToLeft;
 			if (!WrapContents || (horizontal && proposedSize.Width == 0) || (!horizontal && proposedSize.Height == 0)) {
 				foreach (Control control in Controls) {
-					Size control_preferred_size = control.PreferredSize;
+					Size control_preferred_size;
+					if (control.AutoSize)
+						control_preferred_size = control.PreferredSize;
+					else
+						control_preferred_size = control.Size;
 					Padding control_margin = control.Margin;
 					if (horizontal) {
 						width += control_preferred_size.Width + control_margin.Horizontal;
@@ -135,7 +139,11 @@
 				int size_in_other_direction = 0;
 				int increase;
 				foreach (Control control in Controls) {
-					Size control_preferred_size = control.PreferredSize;
+					Size control_preferred_size;
+					if (control.AutoSize)
+						control_preferred_size = control.PreferredSize;
+					else
+						control_preferred_size = control.ExplicitBounds.Size;
 					Padding control_margin = control.Margin;
 					if (horizontal) {
 						increase = control_preferred_size.Width + control_margin.Horizontal;
Index: System.Windows.Forms/ChangeLog
===================================================================
--- System.Windows.Forms/ChangeLog	(revision 107010)
+++ System.Windows.Forms/ChangeLog	(working copy)
@@ -1,3 +1,13 @@
+2008-07-01  Ivan N. Zlatev  <[EMAIL PROTECTED]>
+
+	* Form.cs: 
+	 - (GetPreferredSizeCore): Use PreferredSize only if the 
+	 child is AutoSize, else you the ExplicitBounds.
+	 - (GetPreferredSizeCore): Add up the Padding.
+	* FlowLayoutPanel.cs: (GetPreferredSizeCore): Use PreferredSize 
+	only if the child is AutoSize, else you the ExplicitBounds.
+	[Fixes bug #402849]
+
 2008-07-01  Carlos Alberto Cortez <[EMAIL PROTECTED]>
 
 	* ListViewItem.cs: Restore the initial value of bounds rect to
Index: System.Windows.Forms/Form.cs
===================================================================
--- System.Windows.Forms/Form.cs	(revision 107002)
+++ System.Windows.Forms/Form.cs	(working copy)
@@ -169,21 +169,36 @@
 			Size retsize = Size.Empty;
 			
 			foreach (Control child in Controls) {
+				Size child_preferred_size;
+				if (child.AutoSize)
+					child_preferred_size = child.PreferredSize;
+				else
+					child_preferred_size = child.ExplicitBounds.Size;
+				int child_right = child.Bounds.X + child_preferred_size.Width;
+				int child_bottom = child.Bounds.Y + child_preferred_size.Height;
+
 				if (child.Dock == DockStyle.Fill) {
-					if (child.Bounds.Right > retsize.Width)
-						retsize.Width = child.Bounds.Right;
+					if (child_right > retsize.Width)
+						retsize.Width = child_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;
+				else if (child.Dock != DockStyle.Top && child.Dock != DockStyle.Bottom && child_right > retsize.Width)
+					retsize.Width = child_right + child.Margin.Right;
 
 				if (child.Dock == DockStyle.Fill) {
-					if (child.Bounds.Bottom > retsize.Height)
-						retsize.Height = child.Bounds.Bottom;
+					if (child_bottom > retsize.Height)
+						retsize.Height = child_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;
+				else if (child.Dock != DockStyle.Left && child.Dock != DockStyle.Right && child_bottom > retsize.Height)
+					retsize.Height = child_bottom + child.Margin.Bottom;
 			}
 
+			if (retsize == Size.Empty) { // no child controls
+				retsize.Height += this.Padding.Top;
+				retsize.Width += this.Padding.Left;
+			}
+			retsize.Height += this.Padding.Bottom;
+			retsize.Width += this.Padding.Right;
+
 			return SizeFromClientSize (retsize);
 		}
 
_______________________________________________
Mono-winforms-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-winforms-list

Reply via email to