Properly fill in the whole TableLayoutPanel with dummy controls
authorSteven Boswell II <ulatekh@yahoo.com>
Tue, 24 Jul 2012 18:11:23 +0000 (20:11 +0200)
committerThomas Goldstein <stifu@free.fr>
Tue, 24 Jul 2012 18:14:25 +0000 (20:14 +0200)
mcs/class/Managed.Windows.Forms/System.Windows.Forms.Layout/TableLayout.cs
mcs/class/Managed.Windows.Forms/Test/System.Windows.Forms/TableLayoutTest.cs

index 83b820fa83356cb895f160304b29a19d0bac4190..da1f63d0d38a0ea7a265633956f48d9f08f1aaf2 100644 (file)
@@ -126,11 +126,12 @@ namespace System.Windows.Forms.Layout
 
                                                grid[col, row] = c;
 
-                                               for (int i = 1; i < col_span; i++)
-                                                       grid[col + i, row] = dummy_control;
-
-                                               for (int i = 1; i < row_span; i++)
-                                                       grid[col, row + i] = dummy_control;
+                                               // Fill in the rest of this control's row/column extent with dummy
+                                               // controls, so that other controls don't get put there.
+                                               for (int i = 0; i < col_span; i++)
+                                                       for (int j = 0; j < row_span; j++)
+                                                               if (i != 0 || j != 0)
+                                                                       grid[col + i, row + j] = dummy_control;
                                        }
                                }
                        }
@@ -177,11 +178,12 @@ namespace System.Windows.Forms.Layout
 
                                                        grid[x, y] = c;
 
-                                                       for (int i = 1; i < col_span; i++)
-                                                               grid[x + i, y] = dummy_control;
-
-                                                       for (int i = 1; i < row_span; i++)
-                                                               grid[x, y + i] = dummy_control;
+                                                       // Fill in the rest of this control's row/column extent with dummy
+                                                       // controls, so that other controls don't get put there.
+                                                       for (int i = 0; i < col_span; i++)
+                                                               for (int j = 0; j < row_span; j++)
+                                                                       if (i != 0 || j != 0)
+                                                                               grid[x + i, y + j] = dummy_control;
 
                                                        // I know someone will kill me for using a goto, but 
                                                        // sometimes they really are the easiest way...
index 7e9edf097f336217c8309d8bec8f190ab1140d8e..6f591d23de51f8341b5a6d6854240895a40d2d04 100644 (file)
@@ -600,6 +600,36 @@ namespace MonoTests.System.Windows.Forms
                        Assert.AreEqual (0, p.LayoutSettings.RowCount, "C3");\r
                }\r
 \r
+               [Test]\r
+               public void TestCellPositioning18 ()\r
+               {\r
+                       // A control with both rowspan and columnspan > 1 was getting\r
+                       // other controls put into its extent (i.e. c3 was ending up\r
+                       // at (1,1) instead of (2,1).\r
+                       TableLayoutPanel p = new TableLayoutPanel ();\r
+                       Control c1 = new Button ();\r
+                       Control c2 = new Button ();\r
+                       Control c3 = new Button ();\r
+                       Control c4 = new Button ();\r
+\r
+                       p.ColumnCount = 3;\r
+                       p.RowCount = 4;\r
+\r
+                       p.SetRowSpan (c1, 2);\r
+                       p.SetColumnSpan (c1, 2);\r
+                       p.SetCellPosition (c1, new TableLayoutPanelCellPosition (0, 0));\r
+\r
+                       p.Controls.Add (c1);\r
+                       p.Controls.Add (c2);\r
+                       p.Controls.Add (c3);\r
+                       p.Controls.Add (c4);\r
+\r
+                       Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");\r
+                       Assert.AreEqual (new TableLayoutPanelCellPosition (2, 0), p.GetPositionFromControl (c2), "C2");\r
+                       Assert.AreEqual (new TableLayoutPanelCellPosition (2, 1), p.GetPositionFromControl (c3), "C3");\r
+                       Assert.AreEqual (new TableLayoutPanelCellPosition (0, 2), p.GetPositionFromControl (c4), "C4");\r
+               }\r
+\r
                [Test]\r
                public void TestRowColumnSizes1 ()\r
                {\r