4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (c) 2006 Jonathan Pobst
26 // Jonathan Pobst (monkey@jpobst.com)
33 using System
.Runtime
.Serialization
.Formatters
.Binary
;
34 using System
.Windows
.Forms
;
35 using NUnit
.Framework
;
37 namespace MonoTests
.System
.Windows
.Forms
40 public class TableLayoutTests
: TestHelper
43 public void TestConstruction ()
45 TableLayoutPanel p
= new TableLayoutPanel ();
47 Assert
.AreEqual (BorderStyle
.None
, p
.BorderStyle
, "A1");
48 Assert
.AreEqual (TableLayoutPanelCellBorderStyle
.None
, p
.CellBorderStyle
, "A2");
49 Assert
.AreEqual (0, p
.ColumnCount
, "A3");
50 Assert
.AreEqual (TableLayoutPanelGrowStyle
.AddRows
, p
.GrowStyle
, "A4");
51 Assert
.AreEqual ("System.Windows.Forms.Layout.TableLayout", p
.LayoutEngine
.ToString (), "A5");
52 Assert
.AreEqual ("System.Windows.Forms.TableLayoutSettings", p
.LayoutSettings
.ToString (), "A6");
53 Assert
.AreEqual (0, p
.RowCount
, "A7");
54 Assert
.AreEqual (0, p
.ColumnStyles
.Count
, "A8");
55 Assert
.AreEqual (0, p
.RowStyles
.Count
, "A9");
56 Assert
.AreEqual (new Size (200, 100), p
.Size
, "A10");
60 public void TestPropertySetters ()
62 TableLayoutPanel p
= new TableLayoutPanel ();
64 p
.BorderStyle
= BorderStyle
.Fixed3D
;
65 p
.CellBorderStyle
= TableLayoutPanelCellBorderStyle
.OutsetDouble
;
67 p
.GrowStyle
= TableLayoutPanelGrowStyle
.FixedSize
;
70 Assert
.AreEqual (BorderStyle
.Fixed3D
, p
.BorderStyle
, "A1");
71 Assert
.AreEqual (TableLayoutPanelCellBorderStyle
.OutsetDouble
, p
.CellBorderStyle
, "A2");
72 Assert
.AreEqual (1, p
.ColumnCount
, "A3");
73 Assert
.AreEqual (TableLayoutPanelGrowStyle
.FixedSize
, p
.GrowStyle
, "A4");
74 Assert
.AreEqual (1, p
.RowCount
, "A7");
78 public void TestExtenderMethods ()
80 TableLayoutPanel p
= new TableLayoutPanel ();
81 Control c
= new Button ();
83 Assert
.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p
.GetCellPosition (c
), "A1");
84 Assert
.AreEqual (-1, p
.GetColumn (c
), "A2");
85 Assert
.AreEqual (1, p
.GetColumnSpan (c
), "A3");
86 Assert
.AreEqual (-1, p
.GetRow (c
), "A4");
87 Assert
.AreEqual (1, p
.GetRowSpan (c
), "A5");
89 p
.SetCellPosition (c
, new TableLayoutPanelCellPosition (1, 1));
90 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 1), p
.GetCellPosition (c
), "A6");
93 Assert
.AreEqual (2, p
.GetColumn (c
), "A7");
95 Assert
.AreEqual (2, p
.GetRow (c
), "A9");
97 p
.SetColumnSpan (c
, 2);
98 Assert
.AreEqual (2, p
.GetColumnSpan (c
), "A8");
102 Assert
.AreEqual (2, p
.GetRowSpan (c
), "A10");
104 Assert
.AreEqual (new TableLayoutPanelCellPosition (2, 2), p
.GetCellPosition (c
), "A11");
107 //Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetPositionFromControl (c), "A12");
108 //Assert.AreEqual (c, p.GetControlFromPosition(0, 0), "A13");
112 public void TestColumnStyles ()
114 TableLayoutPanel p
= new TableLayoutPanel ();
116 p
.ColumnStyles
.Add (new ColumnStyle ());
117 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Absolute
));
118 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 20F
));
120 Assert
.AreEqual (3, p
.ColumnStyles
.Count
, "A1");
121 Assert
.AreEqual (SizeType
.AutoSize
, p
.ColumnStyles
[0].SizeType
, "A2");
122 Assert
.AreEqual (0, p
.ColumnStyles
[0].Width
, "A3");
123 Assert
.AreEqual (SizeType
.Absolute
, p
.ColumnStyles
[1].SizeType
, "A4");
124 Assert
.AreEqual (0, p
.ColumnStyles
[1].Width
, "A5");
125 Assert
.AreEqual (SizeType
.Percent
, p
.ColumnStyles
[2].SizeType
, "A6");
126 Assert
.AreEqual (20F
, p
.ColumnStyles
[2].Width
, "A7");
128 p
.ColumnStyles
.Remove (p
.ColumnStyles
[0]);
130 Assert
.AreEqual (2, p
.ColumnStyles
.Count
, "A8");
131 Assert
.AreEqual (SizeType
.Absolute
, p
.ColumnStyles
[0].SizeType
, "A9");
132 Assert
.AreEqual (0, p
.ColumnStyles
[0].Width
, "A10");
133 Assert
.AreEqual (SizeType
.Percent
, p
.ColumnStyles
[1].SizeType
, "A11");
134 Assert
.AreEqual (20F
, p
.ColumnStyles
[1].Width
, "A12");
138 public void TestRowStyles ()
140 TableLayoutPanel p
= new TableLayoutPanel ();
142 p
.RowStyles
.Add (new RowStyle ());
143 p
.RowStyles
.Add (new RowStyle (SizeType
.Absolute
));
144 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 20F
));
146 Assert
.AreEqual (3, p
.RowStyles
.Count
, "A1");
147 Assert
.AreEqual (SizeType
.AutoSize
, p
.RowStyles
[0].SizeType
, "A2");
148 Assert
.AreEqual (0, p
.RowStyles
[0].Height
, "A3");
149 Assert
.AreEqual (SizeType
.Absolute
, p
.RowStyles
[1].SizeType
, "A4");
150 Assert
.AreEqual (0, p
.RowStyles
[1].Height
, "A5");
151 Assert
.AreEqual (SizeType
.Percent
, p
.RowStyles
[2].SizeType
, "A6");
152 Assert
.AreEqual (20F
, p
.RowStyles
[2].Height
, "A7");
154 p
.RowStyles
.Remove (p
.RowStyles
[0]);
156 Assert
.AreEqual (2, p
.RowStyles
.Count
, "A8");
157 Assert
.AreEqual (SizeType
.Absolute
, p
.RowStyles
[0].SizeType
, "A9");
158 Assert
.AreEqual (0, p
.RowStyles
[0].Height
, "A10");
159 Assert
.AreEqual (SizeType
.Percent
, p
.RowStyles
[1].SizeType
, "A11");
160 Assert
.AreEqual (20F
, p
.RowStyles
[1].Height
, "A12");
164 public void TestColumnStyles3 ()
166 // Don't lose the 2nd style
167 TableLayoutPanel p
= new TableLayoutPanel ();
170 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Absolute
, 20F
));
171 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Absolute
, 20F
));
175 Assert
.AreEqual (2, p
.ColumnStyles
.Count
, "A1");
179 public void TestColumnStyles2 ()
181 // Don't lose the 2nd style
182 TableLayoutPanel p
= new TableLayoutPanel ();
185 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Absolute
, 20F
));
189 Assert
.AreEqual (1, p
.ColumnStyles
.Count
, "A2");
193 public void TestCellPositioning ()
196 TableLayoutPanel p
= new TableLayoutPanel ();
197 Control c1
= new Button ();
198 Control c2
= new Button ();
199 Control c3
= new Button ();
200 Control c4
= new Button ();
210 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
211 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 0), p
.GetPositionFromControl (c2
), "C2");
212 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 1), p
.GetPositionFromControl (c3
), "C3");
213 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 1), p
.GetPositionFromControl (c4
), "C4");
217 public void TestCellPositioning2 ()
219 // Growstyle = Add Rows
220 TableLayoutPanel p
= new TableLayoutPanel ();
221 Control c1
= new Button ();
222 Control c2
= new Button ();
223 Control c3
= new Button ();
224 Control c4
= new Button ();
225 Control c5
= new Button ();
226 Control c6
= new Button ();
238 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
239 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 0), p
.GetPositionFromControl (c2
), "C2");
240 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 1), p
.GetPositionFromControl (c3
), "C3");
241 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 1), p
.GetPositionFromControl (c4
), "C4");
242 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 2), p
.GetPositionFromControl (c5
), "C5");
243 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 2), p
.GetPositionFromControl (c6
), "C6");
247 public void TestCellPositioning3 ()
249 // Growstyle = Add Columns
250 TableLayoutPanel p
= new TableLayoutPanel ();
251 p
.GrowStyle
= TableLayoutPanelGrowStyle
.AddColumns
;
253 Control c1
= new Button ();
254 Control c2
= new Button ();
255 Control c3
= new Button ();
256 Control c4
= new Button ();
257 Control c5
= new Button ();
258 Control c6
= new Button ();
270 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
271 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 0), p
.GetPositionFromControl (c2
), "C2");
272 Assert
.AreEqual (new TableLayoutPanelCellPosition (2, 0), p
.GetPositionFromControl (c3
), "C3");
273 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 1), p
.GetPositionFromControl (c4
), "C4");
274 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 1), p
.GetPositionFromControl (c5
), "C5");
275 Assert
.AreEqual (new TableLayoutPanelCellPosition (2, 1), p
.GetPositionFromControl (c6
), "C6");
279 [ExpectedException (typeof (ArgumentException
))]
280 public void TestCellPositioning4 ()
282 // Growstyle = Fixed Size
283 TableLayoutPanel p
= new TableLayoutPanel ();
284 p
.GrowStyle
= TableLayoutPanelGrowStyle
.FixedSize
;
286 Control c1
= new Button ();
287 Control c2
= new Button ();
288 Control c3
= new Button ();
289 Control c4
= new Button ();
290 Control c5
= new Button ();
303 public void TestCellPositioning5 ()
305 // One control have fixed position
306 TableLayoutPanel p
= new TableLayoutPanel ();
307 Control c1
= new Button ();
308 Control c2
= new Button ();
309 Control c3
= new Button ();
310 Control c4
= new Button ();
315 p
.SetCellPosition (c4
, new TableLayoutPanelCellPosition (0, 0));
322 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c4
), "C1");
323 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 0), p
.GetPositionFromControl (c1
), "C2");
324 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 1), p
.GetPositionFromControl (c2
), "C3");
325 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 1), p
.GetPositionFromControl (c3
), "C4");
329 public void TestCellPositioning6 ()
331 // One control has fixed column, it should be ignored
332 TableLayoutPanel p
= new TableLayoutPanel ();
333 Control c1
= new Button ();
334 Control c2
= new Button ();
335 Control c3
= new Button ();
336 Control c4
= new Button ();
348 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
349 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 0), p
.GetPositionFromControl (c2
), "C2");
350 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 1), p
.GetPositionFromControl (c3
), "C3");
351 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 1), p
.GetPositionFromControl (c4
), "C4");
355 public void TestCellPositioning7 ()
357 // One control has fixed column and row
358 TableLayoutPanel p
= new TableLayoutPanel ();
359 Control c1
= new Button ();
360 Control c2
= new Button ();
361 Control c3
= new Button ();
362 Control c4
= new Button ();
375 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
376 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 0), p
.GetPositionFromControl (c2
), "C2");
377 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 1), p
.GetPositionFromControl (c3
), "C3");
378 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 1), p
.GetPositionFromControl (c4
), "C4");
382 public void TestCellPositioning8 ()
385 TableLayoutPanel p
= new TableLayoutPanel ();
386 Control c1
= new Button ();
387 Control c2
= new Button ();
388 Control c3
= new Button ();
393 p
.SetColumnSpan (c1
, 2);
399 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
400 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 1), p
.GetPositionFromControl (c2
), "C2");
401 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 1), p
.GetPositionFromControl (c3
), "C3");
405 public void TestCellPositioning9 ()
408 TableLayoutPanel p
= new TableLayoutPanel ();
409 Control c1
= new Button ();
410 Control c2
= new Button ();
411 Control c3
= new Button ();
416 p
.SetRowSpan (c1
, 2);
422 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
423 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 0), p
.GetPositionFromControl (c2
), "C2");
424 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 1), p
.GetPositionFromControl (c3
), "C3");
428 public void TestCellPositioning10 ()
430 // Column span = 2, but control is in the last column, forces control back into 1st column, next row
431 // I have no clue why c3 shouldn't be in (1,0), but MS says it's not
432 TableLayoutPanel p
= new TableLayoutPanel ();
433 Control c1
= new Button ();
434 Control c2
= new Button ();
435 Control c3
= new Button ();
440 p
.SetColumnSpan (c2
, 2);
446 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
447 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 1), p
.GetPositionFromControl (c2
), "C2");
448 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 2), p
.GetPositionFromControl (c3
), "C3");
452 public void TestCellPositioning11 ()
454 // Row span = 2, but control is in the last row, creates new row
455 TableLayoutPanel p
= new TableLayoutPanel ();
456 Control c1
= new Button ();
457 Control c2
= new Button ();
458 Control c3
= new Button ();
463 p
.SetRowSpan (c3
, 2);
469 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
470 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 0), p
.GetPositionFromControl (c2
), "C2");
471 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 1), p
.GetPositionFromControl (c3
), "C3");
475 public void TestCellPositioning12 ()
477 // Requesting a column greater than ColumnCount, request is ignored
478 TableLayoutPanel p
= new TableLayoutPanel ();
479 Control c1
= new Button ();
480 Control c2
= new Button ();
481 Control c3
= new Button ();
492 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
493 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 0), p
.GetPositionFromControl (c2
), "C2");
494 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 1), p
.GetPositionFromControl (c3
), "C3");
498 public void TestCellPositioning13 ()
500 // Row span = 2, but control is in the last row, creates new row
501 TableLayoutPanel p
= new TableLayoutPanel ();
502 Control c1
= new Button ();
503 Control c2
= new Button ();
504 Control c3
= new Button ();
509 p
.SetRowSpan (c3
, 2);
515 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
516 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 0), p
.GetPositionFromControl (c2
), "C2");
517 Assert
.AreEqual (new TableLayoutPanelCellPosition (2, 0), p
.GetPositionFromControl (c3
), "C3");
521 [Category ("NotWorking")]
522 public void TestCellPositioning14 ()
524 // Col span = 3, fixed grow style
525 TableLayoutPanel p
= new TableLayoutPanel ();
526 p
.GrowStyle
= TableLayoutPanelGrowStyle
.FixedSize
;
527 Control c1
= new Button ();
532 p
.SetColumnSpan (c1
, 3);
536 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
540 public void TestCellPositioning15 ()
542 // Column span = 2, but control is in the last column, forces control back into 1st column, next row
543 // I have no clue why c3 shouldn't be in (1,0), but MS says it's not
544 TableLayoutPanel p
= new TableLayoutPanel ();
545 Control c1
= new Button ();
546 Control c2
= new Button ();
547 Control c3
= new Button ();
552 p
.SetColumnSpan (c2
, 2);
553 p
.SetCellPosition (c2
, new TableLayoutPanelCellPosition (1, 0));
559 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
560 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 1), p
.GetPositionFromControl (c2
), "C2");
561 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 2), p
.GetPositionFromControl (c3
), "C3");
565 public void TestCellPositioning16 ()
567 // Row span = 2, but control is in the last row, creates new row
568 TableLayoutPanel p
= new TableLayoutPanel ();
569 Control c1
= new Button ();
570 Control c2
= new Button ();
571 Control c3
= new Button ();
576 p
.SetRowSpan (c3
, 2);
577 p
.SetCellPosition (c3
, new TableLayoutPanelCellPosition (0, 1));
583 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
584 Assert
.AreEqual (new TableLayoutPanelCellPosition (1, 0), p
.GetPositionFromControl (c2
), "C2");
585 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 1), p
.GetPositionFromControl (c3
), "C3");
589 public void TestCellPositioning17 ()
591 // ColumnCount == RowCount == 0, but control is added at > 0.
592 // The columns and rows are created, but ColumnCount and RowCount remains 0
594 TableLayoutPanel p
= new TableLayoutPanel ();
597 Control c1
= new Button ();
599 p
.Controls
.Add (c1
, 6, 7);
600 Assert
.AreEqual (new TableLayoutPanelCellPosition (6, 7), p
.GetPositionFromControl (c1
), "C1");
601 Assert
.AreEqual (0, p
.LayoutSettings
.ColumnCount
, "C2");
602 Assert
.AreEqual (0, p
.LayoutSettings
.RowCount
, "C3");
606 public void TestCellPositioning18 ()
608 // A control with both rowspan and columnspan > 1 was getting
609 // other controls put into its extent (i.e. c3 was ending up
610 // at (1,1) instead of (2,1).
611 TableLayoutPanel p
= new TableLayoutPanel ();
612 Control c1
= new Button ();
613 Control c2
= new Button ();
614 Control c3
= new Button ();
615 Control c4
= new Button ();
620 p
.SetRowSpan (c1
, 2);
621 p
.SetColumnSpan (c1
, 2);
622 p
.SetCellPosition (c1
, new TableLayoutPanelCellPosition (0, 0));
629 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 0), p
.GetPositionFromControl (c1
), "C1");
630 Assert
.AreEqual (new TableLayoutPanelCellPosition (2, 0), p
.GetPositionFromControl (c2
), "C2");
631 Assert
.AreEqual (new TableLayoutPanelCellPosition (2, 1), p
.GetPositionFromControl (c3
), "C3");
632 Assert
.AreEqual (new TableLayoutPanelCellPosition (0, 2), p
.GetPositionFromControl (c4
), "C4");
636 public void TestRowColumnSizes1 ()
638 // Row span = 2, but control is in the last row, creates new row
639 TableLayoutPanel p
= new TableLayoutPanel ();
640 Control c1
= new Button ();
641 Control c2
= new Button ();
642 Control c3
= new Button ();
647 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 100F
));
653 Assert
.AreEqual (71, p
.GetRowHeights ()[0], "D1");
654 Assert
.AreEqual (29, p
.GetRowHeights ()[1], "D2");
658 public void TestRowColumnSizes2 ()
660 // Row span = 2, but control is in the last row, creates new row
661 TableLayoutPanel p
= new TableLayoutPanel ();
662 Control c1
= new Button ();
663 Control c2
= new Button ();
664 Control c3
= new Button ();
669 p
.RowStyles
.Add (new RowStyle (SizeType
.Absolute
, 100F
));
675 Assert
.AreEqual (100, p
.GetRowHeights ()[0], "D1");
676 Assert
.AreEqual (29, p
.GetRowHeights ()[1], "D2");
680 public void TestRowColumnSizes3 ()
682 // Row span = 2, but control is in the last row, creates new row
683 TableLayoutPanel p
= new TableLayoutPanel ();
684 Control c1
= new Button ();
685 Control c2
= new Button ();
686 Control c3
= new Button ();
687 Control c4
= new Button ();
688 Control c5
= new Button ();
693 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 100F
));
701 Assert
.AreEqual (42, p
.GetRowHeights ()[0], "D1");
702 Assert
.AreEqual (29, p
.GetRowHeights ()[1], "D2");
703 Assert
.AreEqual (29, p
.GetRowHeights ()[2], "D3");
707 public void TestRowColumnSizes4 ()
709 // Row span = 2, but control is in the last row, creates new row
710 TableLayoutPanel p
= new TableLayoutPanel ();
711 Control c1
= new Button ();
712 Control c2
= new Button ();
713 Control c3
= new Button ();
714 Control c4
= new Button ();
715 Control c5
= new Button ();
716 Control c6
= new Button ();
717 Control c7
= new Button ();
722 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 100F
));
732 //Assert.AreEqual (100, p.GetRowHeights ()[0], "D1");
733 Assert
.AreEqual (29, p
.GetRowHeights ()[1], "D2");
734 Assert
.AreEqual (29, p
.GetRowHeights ()[2], "D3");
735 Assert
.AreEqual (29, p
.GetRowHeights ()[3], "D4");
739 public void TestRowColumnSizes5 ()
741 // 2 Absolute Columns/Rows
742 TableLayoutPanel p
= new TableLayoutPanel ();
743 Control c1
= new Button ();
744 Control c2
= new Button ();
745 Control c3
= new Button ();
750 p
.RowStyles
.Add (new RowStyle (SizeType
.Absolute
, 20));
751 p
.RowStyles
.Add (new RowStyle (SizeType
.Absolute
, 30));
752 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Absolute
, 20));
753 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Absolute
, 30));
759 Assert
.AreEqual (20, p
.GetRowHeights ()[0], "D1");
760 Assert
.AreEqual (80, p
.GetRowHeights ()[1], "D2");
761 Assert
.AreEqual (20, p
.GetColumnWidths ()[0], "D3");
762 Assert
.AreEqual (180, p
.GetColumnWidths ()[1], "D4");
766 public void TestRowColumnSizes6 ()
768 // 2 50% Columns/Rows
769 TableLayoutPanel p
= new TableLayoutPanel ();
770 Control c1
= new Button ();
771 Control c2
= new Button ();
772 Control c3
= new Button ();
777 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 50));
778 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 50));
779 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 50));
780 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 50));
786 Assert
.AreEqual (50, p
.GetRowHeights ()[0], "D1");
787 Assert
.AreEqual (50, p
.GetRowHeights ()[1], "D2");
788 Assert
.AreEqual (100, p
.GetColumnWidths ()[0], "D3");
789 Assert
.AreEqual (100, p
.GetColumnWidths ()[1], "D4");
793 public void TestRowColumnSizes7 ()
795 // 1 Absolute and 2 Percent Columns/Rows
796 TableLayoutPanel p
= new TableLayoutPanel ();
797 Control c1
= new Button ();
798 Control c2
= new Button ();
799 Control c3
= new Button ();
804 p
.RowStyles
.Add (new RowStyle (SizeType
.Absolute
, 50));
805 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 50));
806 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 50));
807 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Absolute
, 50));
808 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 50));
809 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 50));
815 Assert
.AreEqual (50, p
.GetRowHeights ()[0], "D1");
816 Assert
.AreEqual (25, p
.GetRowHeights ()[1], "D2");
817 Assert
.AreEqual (25, p
.GetRowHeights ()[2], "D3");
818 Assert
.AreEqual (50, p
.GetColumnWidths ()[0], "D4");
819 Assert
.AreEqual (75, p
.GetColumnWidths ()[1], "D5");
820 Assert
.AreEqual (75, p
.GetColumnWidths ()[2], "D6");
824 public void TestRowColumnSizes8 ()
826 // 1 Absolute and 2 Percent Columns/Rows (with total percents > 100)
827 TableLayoutPanel p
= new TableLayoutPanel ();
828 Control c1
= new Button ();
829 Control c2
= new Button ();
830 Control c3
= new Button ();
835 p
.RowStyles
.Add (new RowStyle (SizeType
.Absolute
, 50));
836 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 100));
837 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 100));
838 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Absolute
, 50));
839 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 100));
840 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 100));
846 Assert
.AreEqual (50, p
.GetRowHeights ()[0], "D1");
847 Assert
.AreEqual (25, p
.GetRowHeights ()[1], "D2");
848 Assert
.AreEqual (25, p
.GetRowHeights ()[2], "D3");
849 Assert
.AreEqual (50, p
.GetColumnWidths ()[0], "D4");
850 Assert
.AreEqual (75, p
.GetColumnWidths ()[1], "D5");
851 Assert
.AreEqual (75, p
.GetColumnWidths ()[2], "D6");
855 public void TestRowColumnSizes9 ()
857 // 1 Absolute and 2 Percent Columns/Rows (with total percents > 100)
858 TableLayoutPanel p
= new TableLayoutPanel ();
859 Control c1
= new Button ();
860 Control c2
= new Button ();
861 Control c3
= new Button ();
866 p
.RowStyles
.Add (new RowStyle (SizeType
.Absolute
, 50));
867 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 80));
868 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 40));
869 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Absolute
, 50));
870 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 80));
871 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 40));
877 Assert
.AreEqual (50, p
.GetRowHeights ()[0], "D1");
878 Assert
.AreEqual (33, p
.GetRowHeights ()[1], "D2");
879 Assert
.AreEqual (17, p
.GetRowHeights ()[2], "D3");
880 Assert
.AreEqual (50, p
.GetColumnWidths ()[0], "D4");
881 Assert
.AreEqual (100, p
.GetColumnWidths ()[1], "D5");
882 Assert
.AreEqual (50, p
.GetColumnWidths ()[2], "D6");
886 public void TestRowColumnSizes10 ()
888 // 2 AutoSize Columns/Rows
889 TableLayoutPanel p
= new TableLayoutPanel ();
890 Control c1
= new Button ();
891 Control c2
= new Button ();
892 Control c3
= new Button ();
897 p
.RowStyles
.Add (new RowStyle (SizeType
.AutoSize
));
898 p
.RowStyles
.Add (new RowStyle (SizeType
.AutoSize
));
899 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.AutoSize
));
900 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.AutoSize
));
906 Assert
.AreEqual (29, p
.GetRowHeights ()[0], "D1");
907 Assert
.AreEqual (71, p
.GetRowHeights ()[1], "D2");
908 Assert
.AreEqual (81, p
.GetColumnWidths ()[0], "D3");
909 Assert
.AreEqual (119, p
.GetColumnWidths ()[1], "D4");
913 public void TestRowColumnSizes11 ()
915 // AutoSize Columns/Rows, and column-spanning controls, but
916 // no control starts in column 1.
917 // Mono's old behavior was for column 1 to have a zero width.
918 TableLayoutPanel p
= new TableLayoutPanel ();
919 Control c1
= new Button ();
920 Control c2
= new Button ();
921 Control c3
= new Button ();
923 c1
.Size
= new Size (150, 25);
924 c2
.Size
= new Size (75, 25);
925 c3
.Size
= new Size (150, 25);
930 p
.RowStyles
.Add (new RowStyle (SizeType
.AutoSize
));
931 p
.RowStyles
.Add (new RowStyle (SizeType
.AutoSize
));
932 p
.RowStyles
.Add (new RowStyle (SizeType
.AutoSize
));
933 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.AutoSize
));
934 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.AutoSize
));
935 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.AutoSize
));
936 p
.ColumnStyles
.Add (new ColumnStyle (SizeType
.AutoSize
));
938 p
.SetColumnSpan (c1
, 2);
939 p
.SetColumnSpan (c3
, 2);
941 p
.Controls
.Add (c1
, 0, 0);
942 p
.Controls
.Add (c2
, 0, 1);
943 p
.Controls
.Add (c3
, 1, 1);
945 // The bug fix gets Mono to behave very closely to .NET,
946 // but not exactly...3 pixels off somewhere...
947 Assert
.AreEqual (31, p
.GetRowHeights ()[0], "D1");
948 Assert
.AreEqual (31, p
.GetRowHeights ()[1], "D2");
949 Assert
.AreEqual (81, p
.GetColumnWidths ()[0], "D3");
950 Assert
.LessOrEqual (75, p
.GetColumnWidths ()[1], "D4");
951 Assert
.GreaterOrEqual (78, p
.GetColumnWidths ()[1], "D5");
952 Assert
.LessOrEqual (78, p
.GetColumnWidths ()[2], "D6");
953 Assert
.GreaterOrEqual (81, p
.GetColumnWidths ()[2], "D7");
957 public void Bug81843 ()
959 Form f
= new Form ();
960 f
.ShowInTaskbar
= false;
962 TableLayoutPanel tableLayoutPanel1
;
967 tableLayoutPanel1
= new TableLayoutPanel ();
968 button2
= new Button ();
969 button4
= new Button ();
970 textBox1
= new TextBox ();
971 tableLayoutPanel1
.SuspendLayout ();
974 tableLayoutPanel1
.AutoSize
= true;
975 tableLayoutPanel1
.ColumnCount
= 3;
976 tableLayoutPanel1
.ColumnStyles
.Add (new ColumnStyle ());
977 tableLayoutPanel1
.ColumnStyles
.Add (new ColumnStyle ());
978 tableLayoutPanel1
.ColumnStyles
.Add (new ColumnStyle ());
979 tableLayoutPanel1
.Controls
.Add (button2
, 0, 1);
980 tableLayoutPanel1
.Controls
.Add (button4
, 2, 1);
981 tableLayoutPanel1
.Controls
.Add (textBox1
, 1, 0);
982 tableLayoutPanel1
.Location
= new Point (0, 0);
983 tableLayoutPanel1
.RowCount
= 2;
984 tableLayoutPanel1
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 50F
));
985 tableLayoutPanel1
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 50F
));
986 tableLayoutPanel1
.Size
= new Size (292, 287);
988 button2
.Size
= new Size (75, 23);
990 button4
.Size
= new Size (75, 23);
992 textBox1
.Dock
= DockStyle
.Fill
;
993 textBox1
.Location
= new Point (84, 3);
994 textBox1
.Multiline
= true;
995 textBox1
.Size
= new Size (94, 137);
997 f
.ClientSize
= new Size (292, 312);
998 f
.Controls
.Add (tableLayoutPanel1
);
1001 tableLayoutPanel1
.ResumeLayout (false);
1002 tableLayoutPanel1
.PerformLayout ();
1003 f
.ResumeLayout (false);
1008 Assert
.AreEqual (new Rectangle (3, 146, 75, 23), button2
.Bounds
, "A1");
1009 Assert
.AreEqual (new Rectangle (184, 146, 75, 23), button4
.Bounds
, "A2");
1010 Assert
.AreEqual (new Rectangle (84, 3, 94, 137), textBox1
.Bounds
, "A3");
1015 [Test
] // From bug #81884
1016 public void CellBorderStyle ()
1018 Form f
= new Form ();
1019 f
.ShowInTaskbar
= false;
1021 TableLayoutPanel p
= new TableLayoutPanel ();
1022 p
= new TableLayoutPanel ();
1024 p
.ColumnStyles
.Add (new ColumnStyle ());
1025 p
.ColumnStyles
.Add (new ColumnStyle ());
1026 p
.ColumnStyles
.Add (new ColumnStyle ());
1027 p
.Dock
= DockStyle
.Top
;
1030 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 50F
));
1031 p
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 50F
));
1034 Label _labelA
= new Label ();
1035 _labelA
.Dock
= DockStyle
.Fill
;
1036 _labelA
.Size
= new Size (95, 20);
1038 p
.Controls
.Add (_labelA
, 0, 0);
1040 Label _labelB
= new Label ();
1041 _labelB
.Dock
= DockStyle
.Fill
;
1042 _labelB
.Size
= new Size (95, 20);
1044 p
.Controls
.Add (_labelB
, 1, 0);
1046 Label _labelC
= new Label ();
1047 _labelC
.Dock
= DockStyle
.Fill
;
1048 _labelC
.Size
= new Size (95, 20);
1050 p
.Controls
.Add (_labelC
, 2, 0);
1052 Label _labelD
= new Label ();
1053 _labelD
.Dock
= DockStyle
.Fill
;
1054 _labelD
.Size
= new Size (95, 20);
1056 p
.Controls
.Add (_labelD
, 0, 1);
1058 Label _labelE
= new Label ();
1059 _labelE
.Dock
= DockStyle
.Fill
;
1060 _labelE
.Size
= new Size (95, 20);
1062 p
.Controls
.Add (_labelE
, 1, 1);
1064 Label _labelF
= new Label ();
1065 _labelF
.Dock
= DockStyle
.Fill
;
1066 _labelF
.Size
= new Size (95, 20);
1068 p
.Controls
.Add (_labelF
, 2, 1);
1070 _labelA
.BackColor
= Color
.Red
;
1071 _labelB
.BackColor
= Color
.Orange
;
1072 _labelC
.BackColor
= Color
.Yellow
;
1073 _labelD
.BackColor
= Color
.Green
;
1074 _labelE
.BackColor
= Color
.Blue
;
1075 _labelF
.BackColor
= Color
.Purple
;
1079 Assert
.AreEqual (new Rectangle (3, 0, 95, 100), _labelA
.Bounds
, "A1");
1080 Assert
.AreEqual (new Rectangle (104, 0, 95, 100), _labelB
.Bounds
, "A2");
1081 Assert
.AreEqual (new Rectangle (205, 0, 95, 100), _labelC
.Bounds
, "A3");
1082 Assert
.AreEqual (new Rectangle (3, 100, 95, 100), _labelD
.Bounds
, "A4");
1083 Assert
.AreEqual (new Rectangle (104, 100, 95, 100), _labelE
.Bounds
, "A5");
1084 Assert
.AreEqual (new Rectangle (205, 100, 95, 100), _labelF
.Bounds
, "A6");
1086 p
.CellBorderStyle
= TableLayoutPanelCellBorderStyle
.Single
;
1087 Assert
.AreEqual (new Rectangle (4, 1, 95, 98), _labelA
.Bounds
, "A7");
1088 Assert
.AreEqual (new Rectangle (106, 1, 95, 98), _labelB
.Bounds
, "A8");
1089 Assert
.AreEqual (new Rectangle (208, 1, 95, 98), _labelC
.Bounds
, "A9");
1090 Assert
.AreEqual (new Rectangle (4, 100, 95, 99), _labelD
.Bounds
, "A10");
1091 Assert
.AreEqual (new Rectangle (106, 100, 95, 99), _labelE
.Bounds
, "A11");
1092 Assert
.AreEqual (new Rectangle (208, 100, 95, 99), _labelF
.Bounds
, "A12");
1094 p
.CellBorderStyle
= TableLayoutPanelCellBorderStyle
.Inset
;
1095 Assert
.AreEqual (new Rectangle (5, 2, 95, 97), _labelA
.Bounds
, "A13");
1096 Assert
.AreEqual (new Rectangle (108, 2, 95, 97), _labelB
.Bounds
, "A14");
1097 Assert
.AreEqual (new Rectangle (211, 2, 95, 97), _labelC
.Bounds
, "A15");
1098 Assert
.AreEqual (new Rectangle (5, 101, 95, 97), _labelD
.Bounds
, "A16");
1099 Assert
.AreEqual (new Rectangle (108, 101, 95, 97), _labelE
.Bounds
, "A17");
1100 Assert
.AreEqual (new Rectangle (211, 101, 95, 97), _labelF
.Bounds
, "A18");
1102 p
.CellBorderStyle
= TableLayoutPanelCellBorderStyle
.InsetDouble
;
1103 Assert
.AreEqual (new Rectangle (6, 3, 95, 95), _labelA
.Bounds
, "A19");
1104 Assert
.AreEqual (new Rectangle (110, 3, 95, 95), _labelB
.Bounds
, "A20");
1105 Assert
.AreEqual (new Rectangle (214, 3, 95, 95), _labelC
.Bounds
, "A21");
1106 Assert
.AreEqual (new Rectangle (6, 101, 95, 96), _labelD
.Bounds
, "A22");
1107 Assert
.AreEqual (new Rectangle (110, 101, 95, 96), _labelE
.Bounds
, "A23");
1108 Assert
.AreEqual (new Rectangle (214, 101, 95, 96), _labelF
.Bounds
, "A24");
1110 p
.CellBorderStyle
= TableLayoutPanelCellBorderStyle
.Outset
;
1111 Assert
.AreEqual (new Rectangle (5, 2, 95, 97), _labelA
.Bounds
, "A25");
1112 Assert
.AreEqual (new Rectangle (108, 2, 95, 97), _labelB
.Bounds
, "A26");
1113 Assert
.AreEqual (new Rectangle (211, 2, 95, 97), _labelC
.Bounds
, "A27");
1114 Assert
.AreEqual (new Rectangle (5, 101, 95, 97), _labelD
.Bounds
, "A28");
1115 Assert
.AreEqual (new Rectangle (108, 101, 95, 97), _labelE
.Bounds
, "A29");
1116 Assert
.AreEqual (new Rectangle (211, 101, 95, 97), _labelF
.Bounds
, "A30");
1118 p
.CellBorderStyle
= TableLayoutPanelCellBorderStyle
.OutsetDouble
;
1119 Assert
.AreEqual (new Rectangle (6, 3, 95, 95), _labelA
.Bounds
, "A31");
1120 Assert
.AreEqual (new Rectangle (110, 3, 95, 95), _labelB
.Bounds
, "A32");
1121 Assert
.AreEqual (new Rectangle (214, 3, 95, 95), _labelC
.Bounds
, "A33");
1122 Assert
.AreEqual (new Rectangle (6, 101, 95, 96), _labelD
.Bounds
, "A34");
1123 Assert
.AreEqual (new Rectangle (110, 101, 95, 96), _labelE
.Bounds
, "A35");
1124 Assert
.AreEqual (new Rectangle (214, 101, 95, 96), _labelF
.Bounds
, "A36");
1126 p
.CellBorderStyle
= TableLayoutPanelCellBorderStyle
.OutsetPartial
;
1127 Assert
.AreEqual (new Rectangle (6, 3, 95, 95), _labelA
.Bounds
, "A37");
1128 Assert
.AreEqual (new Rectangle (110, 3, 95, 95), _labelB
.Bounds
, "A38");
1129 Assert
.AreEqual (new Rectangle (214, 3, 95, 95), _labelC
.Bounds
, "A39");
1130 Assert
.AreEqual (new Rectangle (6, 101, 95, 96), _labelD
.Bounds
, "A40");
1131 Assert
.AreEqual (new Rectangle (110, 101, 95, 96), _labelE
.Bounds
, "A41");
1132 Assert
.AreEqual (new Rectangle (214, 101, 95, 96), _labelF
.Bounds
, "A42");
1138 public void Bug81936 ()
1140 Form f
= new Form ();
1141 f
.ShowInTaskbar
= false;
1143 TableLayoutPanel tableLayoutPanel1
;
1147 tableLayoutPanel1
= new TableLayoutPanel ();
1148 button2
= new Label ();
1149 button4
= new Label ();
1150 button2
.Text
= "Test1";
1151 button4
.Text
= "Test2";
1152 button2
.Anchor
= AnchorStyles
.Left
;
1153 button4
.Anchor
= AnchorStyles
.Left
;
1154 button2
.Height
= 14;
1155 button4
.Height
= 14;
1156 tableLayoutPanel1
.SuspendLayout ();
1159 tableLayoutPanel1
.ColumnCount
= 1;
1160 tableLayoutPanel1
.ColumnStyles
.Add (new ColumnStyle ());
1161 tableLayoutPanel1
.Controls
.Add (button2
, 0, 0);
1162 tableLayoutPanel1
.Controls
.Add (button4
, 0, 1);
1163 tableLayoutPanel1
.Location
= new Point (0, 0);
1164 tableLayoutPanel1
.RowCount
= 2;
1165 tableLayoutPanel1
.RowStyles
.Add (new RowStyle (SizeType
.Absolute
, 28F
));
1166 tableLayoutPanel1
.RowStyles
.Add (new RowStyle (SizeType
.Absolute
, 28F
));
1167 tableLayoutPanel1
.Size
= new Size (292, 56);
1169 f
.ClientSize
= new Size (292, 312);
1170 f
.Controls
.Add (tableLayoutPanel1
);
1173 tableLayoutPanel1
.ResumeLayout (false);
1174 tableLayoutPanel1
.PerformLayout ();
1175 f
.ResumeLayout (false);
1180 Assert
.AreEqual (new Rectangle (3, 7, 100, 14), button2
.Bounds
, "A1");
1181 Assert
.AreEqual (new Rectangle (3, 35, 100, 14), button4
.Bounds
, "A2");
1187 public void Bug82605 ()
1189 Form f
= new Form ();
1190 f
.ShowInTaskbar
= false;
1192 Label l
= new Label ();
1194 TableLayoutPanel table
= new TableLayoutPanel ();
1195 table
.ColumnCount
= 1;
1196 table
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 100F
));
1199 table
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 100F
));
1200 table
.RowStyles
.Add (new RowStyle (SizeType
.Absolute
, 20F
));
1202 table
.Controls
.Add (l
, 0, 1);
1203 table
.Location
= new Point (0, 0);
1206 l
.Anchor
= AnchorStyles
.Left
| AnchorStyles
.Right
;
1208 l
.Location
= new Point (3, 352);
1209 l
.Size
= new Size (578, 13);
1211 l
.TextAlign
= ContentAlignment
.MiddleCenter
;
1213 f
.Controls
.Add (table
);
1216 // Height is font dependent, but this bug is about the width anyways
1217 Assert
.AreEqual (244, l
.Width
, "A1");
1222 [Test
] // bug #82040
1223 public void ShowNoChildren ()
1225 Form form
= new Form ();
1226 form
.ShowInTaskbar
= false;
1228 TableLayoutPanel tableLayoutPanel
= new TableLayoutPanel ();
1229 tableLayoutPanel
.ColumnCount
= 3;
1230 tableLayoutPanel
.Dock
= DockStyle
.Fill
;
1231 tableLayoutPanel
.RowCount
= 11;
1232 form
.Controls
.Add (tableLayoutPanel
);
1239 [Test
] // bug #82041
1240 public void DontCallResumeLayout ()
1242 Form form
= new Form ();
1243 form
.ShowInTaskbar
= false;
1245 TableLayoutPanel tableLayoutPanel
= new TableLayoutPanel ();
1246 form
.Controls
.Add (tableLayoutPanel
);
1247 tableLayoutPanel
.SuspendLayout ();
1248 tableLayoutPanel
.ColumnCount
= 3;
1249 tableLayoutPanel
.Dock
= DockStyle
.Fill
;
1250 tableLayoutPanel
.RowCount
= 11;
1251 tableLayoutPanel
.Controls
.Add (new Button ());
1258 [Test
] // bug #346246
1259 public void AutoSizePanelVertical ()
1261 Form f
= new Form ();
1262 f
.ShowInTaskbar
= false;
1264 TableLayoutPanel tlp
= new TableLayoutPanel ();
1265 tlp
.AutoSize
= true;
1266 tlp
.AutoSizeMode
= AutoSizeMode
.GrowAndShrink
;
1267 tlp
.ColumnCount
= 1;
1268 tlp
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 100F
));
1269 tlp
.Location
= new Point (12, 12);
1270 tlp
.Name
= "tableLayoutPanel1";
1272 tlp
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 50F
));
1273 tlp
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 50F
));
1274 tlp
.Size
= new Size (139, 182);
1277 f
.Controls
.Add (tlp
);
1279 Button b
= new Button ();
1280 b
.Size
= new Size (100, 100);
1281 tlp
.Controls
.Add (b
, 0, 0);
1283 PictureBox p
= new PictureBox ();
1284 p
.Size
= new Size (100, 100);
1285 tlp
.Controls
.Add (p
,0,1);
1289 Assert
.AreEqual (new Rectangle (12, 12, 106, 212), tlp
.Bounds
, "A1");
1290 Assert
.AreEqual (new Rectangle (3, 3, 100, 100), b
.Bounds
, "A2");
1291 Assert
.AreEqual (new Rectangle (3, 109, 100, 100), p
.Bounds
, "A3");
1296 Assert
.AreEqual (new Rectangle (12, 12, 126, 252), tlp
.Bounds
, "B1");
1297 Assert
.AreEqual (new Rectangle (3, 3, 120, 120), b
.Bounds
, "B2");
1298 Assert
.AreEqual (new Rectangle (3, 129, 100, 100), p
.Bounds
, "B3");
1303 Assert
.AreEqual (new Rectangle (12, 12, 126, 252), tlp
.Bounds
, "C1");
1304 Assert
.AreEqual (new Rectangle (3, 3, 120, 120), b
.Bounds
, "C2");
1305 Assert
.AreEqual (new Rectangle (3, 129, 120, 120), p
.Bounds
, "C3");
1310 [Test
] // bug #346246
1311 public void AutoSizePanelHorizontal ()
1313 Form f
= new Form ();
1314 f
.ShowInTaskbar
= false;
1316 TableLayoutPanel tlp
= new TableLayoutPanel ();
1317 tlp
.AutoSize
= true;
1318 tlp
.AutoSizeMode
= AutoSizeMode
.GrowAndShrink
;
1319 tlp
.ColumnCount
= 2;
1320 tlp
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 50F
));
1321 tlp
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 50F
));
1322 tlp
.Location
= new Point (12, 12);
1323 tlp
.Name
= "tableLayoutPanel1";
1325 tlp
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 100F
));
1326 tlp
.Size
= new Size (139, 182);
1329 f
.Controls
.Add (tlp
);
1331 Button b
= new Button ();
1332 b
.Size
= new Size (100, 100);
1333 tlp
.Controls
.Add (b
, 0, 0);
1335 PictureBox p
= new PictureBox ();
1336 p
.Size
= new Size (100, 100);
1337 tlp
.Controls
.Add (p
, 1, 0);
1341 Assert
.AreEqual (new Rectangle (12, 12, 212, 106), tlp
.Bounds
, "A1");
1342 Assert
.AreEqual (new Rectangle (3, 3, 100, 100), b
.Bounds
, "A2");
1343 Assert
.AreEqual (new Rectangle (109, 3, 100, 100), p
.Bounds
, "A3");
1348 Assert
.AreEqual (new Rectangle (12, 12, 252, 126), tlp
.Bounds
, "B1");
1349 Assert
.AreEqual (new Rectangle (3, 3, 120, 120), b
.Bounds
, "B2");
1350 Assert
.AreEqual (new Rectangle (129, 3, 100, 100), p
.Bounds
, "B3");
1355 Assert
.AreEqual (new Rectangle (12, 12, 252, 126), tlp
.Bounds
, "C1");
1356 Assert
.AreEqual (new Rectangle (3, 3, 120, 120), b
.Bounds
, "C2");
1357 Assert
.AreEqual (new Rectangle (129, 3, 120, 120), p
.Bounds
, "C3");
1363 public void Bug354676 ()
1365 Form f
= new Form ();
1367 TableLayoutPanel tlp
= new TableLayoutPanel ();
1368 tlp
.Dock
= DockStyle
.Fill
;
1369 tlp
.Padding
= new Padding (40);
1371 tlp
.ColumnCount
= 1;
1372 f
.Controls
.Add (tlp
);
1374 Button b1
= new Button ();
1375 tlp
.Controls
.Add (b1
);
1377 Button b2
= new Button ();
1378 tlp
.Controls
.Add (b2
);
1382 Assert
.AreEqual (new Rectangle (43, 43, 75, 23), b1
.Bounds
, "A1");
1383 Assert
.AreEqual (new Rectangle (43, 72, 75, 23), b2
.Bounds
, "A2");
1390 public void Bug355408 ()
1392 Form f
= new Form ();
1393 f
.ClientSize
= new Size (300, 300);
1395 TableLayoutPanel tlp
= new TableLayoutPanel ();
1396 tlp
.Dock
= DockStyle
.Fill
;
1398 tlp
.ColumnCount
= 2;
1399 f
.Controls
.Add (tlp
);
1401 Button b1
= new Button ();
1402 tlp
.Controls
.Add (b1
);
1404 Button b2
= new Button ();
1405 tlp
.Controls
.Add (b2
);
1407 Button b3
= new Button ();
1408 b3
.Dock
= DockStyle
.Fill
;
1410 tlp
.SetColumnSpan (b3
, 2);
1411 tlp
.Controls
.Add (b3
);
1415 Assert
.AreEqual (new Rectangle (3, 3, 75, 23), b1
.Bounds
, "A1");
1416 Assert
.AreEqual (new Rectangle (84, 3, 75, 23), b2
.Bounds
, "A2");
1417 Assert
.AreEqual (new Rectangle (3, 32, 294, 265), b3
.Bounds
, "A3");
1424 public void Bug402651 ()
1426 Form f
= new Form ();
1427 f
.ClientSize
= new Size (300, 300);
1429 TableLayoutPanel tlp
= new TableLayoutPanel ();
1430 tlp
.Dock
= DockStyle
.Fill
;
1432 tlp
.RowStyles
.Add (new RowStyle (SizeType
.Percent
, 100F
));
1433 tlp
.RowStyles
.Add (new RowStyle (SizeType
.AutoSize
));
1434 f
.Controls
.Add (tlp
);
1436 Button b1
= new Button ();
1437 b1
.Text
= String
.Empty
;
1438 b1
.Dock
= DockStyle
.Fill
;
1439 tlp
.Controls
.Add (b1
, 0, 0);
1441 Button b2
= new Button ();
1442 b2
.Text
= String
.Empty
;
1443 b2
.Size
= new Size (100, 100);
1444 b2
.Anchor
= AnchorStyles
.None
;
1445 b2
.Dock
= DockStyle
.None
;
1447 tlp
.Controls
.Add (b2
, 0, 1);
1452 Assert
.AreEqual (new Size (100, 100), b2
.Size
, "A1");
1455 b2
.Anchor
= AnchorStyles
.Left
;
1457 Assert
.AreEqual (new Size (100, 100), b2
.Size
, "A2");
1463 public void Bug354672 ()
1465 Form f
= new Form ();
1466 f
.ClientSize
= new Size (300, 300);
1468 TableLayoutPanel tlp
= new TableLayoutPanel ();
1469 tlp
.AutoSize
= true;
1470 tlp
.ColumnCount
= 2;
1472 f
.Controls
.Add (tlp
);
1474 TextBox t1
= new TextBox ();
1475 t1
.Dock
= DockStyle
.Fill
;
1476 tlp
.Controls
.Add (t1
);
1478 TextBox t2
= new TextBox ();
1479 t2
.Dock
= DockStyle
.Fill
;
1480 tlp
.Controls
.Add (t2
);
1482 Assert
.AreEqual (new Size (212, t1
.Height
+ 6), tlp
.PreferredSize
, "A1");
1488 public void Bug354672More ()
1490 Form f
= new Form ();
1491 f
.ClientSize
= new Size (300, 300);
1493 TableLayoutPanel tlp
= new TableLayoutPanel ();
1494 tlp
.AutoSize
= true;
1495 tlp
.ColumnCount
= 2;
1497 tlp
.ColumnStyles
.Add (new ColumnStyle (SizeType
.AutoSize
));
1498 tlp
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 50f
));
1500 f
.Controls
.Add (tlp
);
1502 TextBox t1
= new TextBox ();
1503 t1
.Dock
= DockStyle
.Fill
;
1504 tlp
.Controls
.Add (t1
);
1506 TextBox t2
= new TextBox ();
1507 t2
.Dock
= DockStyle
.Fill
;
1508 tlp
.Controls
.Add (t2
);
1510 Assert
.AreEqual (new Size (212, t1
.Height
+ 6), tlp
.PreferredSize
, "A1");
1516 public void Bug367249 ()
1518 // Setting a colspan greater than the number of columns was
1519 // causing an IOORE, this test just should not exception
1520 TableLayoutPanel LayoutPanel
= new TableLayoutPanel ();
1521 LayoutPanel
.ColumnCount
= 1;
1522 LayoutPanel
.RowCount
= 2;
1524 Button OkButton
= new Button ();
1525 OkButton
.Text
= "OK";
1526 LayoutPanel
.Controls
.Add (OkButton
);
1527 LayoutPanel
.SetColumnSpan (OkButton
, 3);
1531 public void Bug396141 ()
1533 // The issue is the user has set the RowCount to 0, but after
1534 // we arrange the controls, we have 1 row. GetPreferredSize (for
1535 // AutoSize) was using 0 instead of 1.
1537 Form f
= new Form ();
1538 f
.ClientSize
= new Size (300, 300);
1539 f
.ShowInTaskbar
= false;
1541 TableLayoutPanel tlp
= new TableLayoutPanel ();
1542 tlp
.AutoSize
= true;
1543 tlp
.AutoSizeMode
= AutoSizeMode
.GrowAndShrink
;
1544 tlp
.ColumnCount
= 2;
1547 f
.Controls
.Add (tlp
);
1549 TextBox t1
= new TextBox ();
1550 t1
.Dock
= DockStyle
.Fill
;
1551 tlp
.Controls
.Add (t1
);
1553 TextBox t2
= new TextBox ();
1554 t2
.Dock
= DockStyle
.Fill
;
1555 tlp
.Controls
.Add (t2
);
1559 Assert
.IsTrue (tlp
.Height
> 0, "Height must be > 0");
1560 Assert
.IsTrue (tlp
.Width
> 0, "Width must be > 0");
1566 public void Bug396433 ()
1568 // We were not taking the CellBorderStyle into account when calculating
1569 // the preferred size.
1570 Form f
= new Form ();
1571 f
.ClientSize
= new Size (300, 300);
1572 f
.ShowInTaskbar
= false;
1574 TableLayoutPanel tlp
= new TableLayoutPanel ();
1575 tlp
.AutoSize
= true;
1576 tlp
.AutoSizeMode
= AutoSizeMode
.GrowAndShrink
;
1577 tlp
.ColumnCount
= 2;
1580 f
.Controls
.Add (tlp
);
1582 Button t1
= new Button ();
1583 tlp
.Controls
.Add (t1
);
1585 Button t2
= new Button ();
1586 tlp
.Controls
.Add (t2
);
1590 Assert
.AreEqual (new Size (162, 29), tlp
.PreferredSize
, "A1");
1592 tlp
.CellBorderStyle
= TableLayoutPanelCellBorderStyle
.Single
;
1594 Assert
.AreEqual (new Size (165, 31), tlp
.PreferredSize
, "A2");
1600 public void IgnoreAutoSizeMode ()
1602 // It would seem that AutoSizeMode for a TableLayoutPanel is always
1603 // treated as GrowAndShrink
1604 Form f
= new Form ();
1605 f
.ClientSize
= new Size (300, 300);
1606 f
.ShowInTaskbar
= false;
1608 TableLayoutPanel tlp
= new TableLayoutPanel ();
1609 tlp
.AutoSize
= true;
1610 tlp
.Dock
= DockStyle
.Top
;
1611 tlp
.ColumnCount
= 1;
1614 f
.Controls
.Add (tlp
);
1616 Button t1
= new Button ();
1617 tlp
.Controls
.Add (t1
);
1621 Assert
.AreEqual (29, tlp
.Height
, "A1");
1623 tlp
.AutoSizeMode
= AutoSizeMode
.GrowAndShrink
;
1625 Assert
.AreEqual (29, tlp
.Height
, "A2");
1631 public void TestTableLayoutStyleOwned ()
1634 ColumnStyle style
= new ColumnStyle ();
1635 TableLayoutColumnStyleCollection coll
= new TableLayoutPanel ().ColumnStyles
;
1637 TableLayoutColumnStyleCollection coll2
= new TableLayoutPanel ().ColumnStyles
;
1640 } catch (ArgumentException ex
) {
1645 RowStyle style
= new RowStyle ();
1646 TableLayoutRowStyleCollection coll
= new TableLayoutPanel ().RowStyles
;
1648 TableLayoutRowStyleCollection coll2
= new TableLayoutPanel ().RowStyles
;
1651 } catch (ArgumentException ex
) {
1656 [Test
] // Novell bug #497562
1657 public void TestLayoutSettingsSetter ()
1659 using (var tlp
= new TableLayoutPanel ()) {
1660 TableLayoutSettings tls
;
1662 using (var ms
= new MemoryStream ()) {
1663 var formatter
= new BinaryFormatter ();
1664 formatter
.Serialize (ms
, tlp
.LayoutSettings
);
1668 tls
= (TableLayoutSettings
) formatter
.Deserialize (ms
);
1671 tlp
.LayoutSettings
= tls
;
1672 tlp
.LayoutSettings
= tls
; // Should not throw an exception
1677 public void XamarinBug18638 ()
1679 // Spanning items should not have their entire width assigned to the first column in the span.
1680 TableLayoutPanel tlp
= new TableLayoutPanel ();
1681 tlp
.SuspendLayout ();
1682 tlp
.Size
= new Size(291, 100);
1683 tlp
.AutoSize
= true;
1684 tlp
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Absolute
, 60));
1685 tlp
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Percent
, 100));
1686 tlp
.ColumnStyles
.Add (new ColumnStyle (SizeType
.Absolute
, 45));
1687 tlp
.ColumnCount
= 3;
1688 tlp
.RowStyles
.Add (new RowStyle (SizeType
.AutoSize
));
1689 var label1
= new Label {AutoSize = true, Text = @"This line spans all three columns in the table!"}
;
1690 tlp
.Controls
.Add (label1
, 0, 0);
1691 tlp
.SetColumnSpan (label1
, 3);
1692 tlp
.RowStyles
.Add (new RowStyle (SizeType
.AutoSize
));
1694 var label2
= new Label {AutoSize = true, Text = @"This line spans columns two and three."}
;
1695 tlp
.Controls
.Add (label2
, 1, 1);
1696 tlp
.SetColumnSpan (label2
, 2);
1698 AddTableRow (tlp
, "First Row", "This is a test");
1699 AddTableRow (tlp
, "Row 2", "This is another test");
1700 tlp
.ResumeLayout ();
1702 var widths
= tlp
.GetColumnWidths ();
1703 Assert
.AreEqual (4, tlp
.RowCount
, "X18638-1");
1704 Assert
.AreEqual (3, tlp
.ColumnCount
, "X18638-2");
1705 Assert
.AreEqual (60, widths
[0], "X18638-3");
1706 Assert
.Greater (label2
.Width
, widths
[1], "X18638-5");
1707 Assert
.AreEqual (45, widths
[2], "X18638-4");
1710 private void AddTableRow(TableLayoutPanel tlp
, string label
, string text
)
1712 tlp
.SuspendLayout ();
1713 int row
= tlp
.RowCount
;
1714 tlp
.RowStyles
.Add (new RowStyle (SizeType
.AutoSize
));
1715 var first
= new Label {AutoSize = true, Dock = DockStyle.Fill, Text = label}
;
1716 tlp
.Controls
.Add (first
, 0, row
);
1717 var second
= new TextBox {AutoSize = true, Text = text, Dock = DockStyle.Fill, Multiline = true}
;
1718 tlp
.Controls
.Add (second
, 1, row
);
1719 var third
= new Button {Text = @"DEL", Dock = DockStyle.Fill}
;
1720 tlp
.Controls
.Add (third
, 2, row
);
1721 tlp
.RowCount
= row
+ 1;
1722 tlp
.ResumeLayout ();