Fix bugs in sizing TableLayoutPanel (Xamarin bug 18638)
[mono-project.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / TableLayoutTest.cs
blob2d5ad06b0673fbed2ca2a782cd72f48c87889d18
1 //
2 // TableLayoutTests.cs
3 //
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:
11 //
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
14 //
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
25 // Authors:
26 // Jonathan Pobst (monkey@jpobst.com)
29 #if NET_2_0
30 using System;
31 using System.Drawing;
32 using System.IO;
33 using System.Runtime.Serialization.Formatters.Binary;
34 using System.Windows.Forms;
35 using NUnit.Framework;
37 namespace MonoTests.System.Windows.Forms
39 [TestFixture]
40 public class TableLayoutTests : TestHelper
42 [Test]
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");
59 [Test]
60 public void TestPropertySetters ()
62 TableLayoutPanel p = new TableLayoutPanel ();
64 p.BorderStyle = BorderStyle.Fixed3D;
65 p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;
66 p.ColumnCount = 1;
67 p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;
68 p.RowCount = 1;
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");
77 [Test]
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");
92 p.SetColumn (c, 2);
93 Assert.AreEqual (2, p.GetColumn (c), "A7");
94 p.SetRow (c, 2);
95 Assert.AreEqual (2, p.GetRow (c), "A9");
97 p.SetColumnSpan (c, 2);
98 Assert.AreEqual (2, p.GetColumnSpan (c), "A8");
101 p.SetRowSpan (c, 2);
102 Assert.AreEqual (2, p.GetRowSpan (c), "A10");
104 Assert.AreEqual (new TableLayoutPanelCellPosition (2, 2), p.GetCellPosition (c), "A11");
106 // ???????
107 //Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetPositionFromControl (c), "A12");
108 //Assert.AreEqual (c, p.GetControlFromPosition(0, 0), "A13");
111 [Test]
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");
137 [Test]
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");
163 [Test]
164 public void TestColumnStyles3 ()
166 // Don't lose the 2nd style
167 TableLayoutPanel p = new TableLayoutPanel ();
169 p.ColumnCount = 2;
170 p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));
171 p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));
173 p.ColumnCount = 1;
175 Assert.AreEqual (2, p.ColumnStyles.Count, "A1");
178 [Test]
179 public void TestColumnStyles2 ()
181 // Don't lose the 2nd style
182 TableLayoutPanel p = new TableLayoutPanel ();
184 p.ColumnCount = 1;
185 p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));
187 p.ColumnCount = 2;
189 Assert.AreEqual (1, p.ColumnStyles.Count, "A2");
192 [Test]
193 public void TestCellPositioning ()
195 // Standard Add
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 ();
202 p.ColumnCount = 2;
203 p.RowCount = 2;
205 p.Controls.Add (c1);
206 p.Controls.Add (c2);
207 p.Controls.Add (c3);
208 p.Controls.Add (c4);
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");
216 [Test]
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 ();
228 p.ColumnCount = 2;
229 p.RowCount = 2;
231 p.Controls.Add (c1);
232 p.Controls.Add (c2);
233 p.Controls.Add (c3);
234 p.Controls.Add (c4);
235 p.Controls.Add (c5);
236 p.Controls.Add (c6);
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");
246 [Test]
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 ();
260 p.ColumnCount = 2;
261 p.RowCount = 2;
263 p.Controls.Add (c1);
264 p.Controls.Add (c2);
265 p.Controls.Add (c3);
266 p.Controls.Add (c4);
267 p.Controls.Add (c5);
268 p.Controls.Add (c6);
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");
278 [Test]
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 ();
292 p.ColumnCount = 2;
293 p.RowCount = 2;
295 p.Controls.Add (c1);
296 p.Controls.Add (c2);
297 p.Controls.Add (c3);
298 p.Controls.Add (c4);
299 p.Controls.Add (c5);
302 [Test]
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 ();
312 p.ColumnCount = 2;
313 p.RowCount = 2;
315 p.SetCellPosition (c4, new TableLayoutPanelCellPosition (0, 0));
317 p.Controls.Add (c1);
318 p.Controls.Add (c2);
319 p.Controls.Add (c3);
320 p.Controls.Add (c4);
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");
328 [Test]
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 ();
338 p.ColumnCount = 2;
339 p.RowCount = 2;
341 p.SetColumn (c3, 1);
343 p.Controls.Add (c1);
344 p.Controls.Add (c2);
345 p.Controls.Add (c3);
346 p.Controls.Add (c4);
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");
354 [Test]
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 ();
364 p.ColumnCount = 2;
365 p.RowCount = 2;
367 p.SetColumn (c3, 1);
368 p.SetRow (c3, 1);
370 p.Controls.Add (c1);
371 p.Controls.Add (c2);
372 p.Controls.Add (c3);
373 p.Controls.Add (c4);
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");
381 [Test]
382 public void TestCellPositioning8 ()
384 // Column span
385 TableLayoutPanel p = new TableLayoutPanel ();
386 Control c1 = new Button ();
387 Control c2 = new Button ();
388 Control c3 = new Button ();
390 p.ColumnCount = 2;
391 p.RowCount = 2;
393 p.SetColumnSpan (c1, 2);
395 p.Controls.Add (c1);
396 p.Controls.Add (c2);
397 p.Controls.Add (c3);
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");
404 [Test]
405 public void TestCellPositioning9 ()
407 // Row span
408 TableLayoutPanel p = new TableLayoutPanel ();
409 Control c1 = new Button ();
410 Control c2 = new Button ();
411 Control c3 = new Button ();
413 p.ColumnCount = 2;
414 p.RowCount = 2;
416 p.SetRowSpan (c1, 2);
418 p.Controls.Add (c1);
419 p.Controls.Add (c2);
420 p.Controls.Add (c3);
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");
427 [Test]
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 ();
437 p.ColumnCount = 2;
438 p.RowCount = 2;
440 p.SetColumnSpan (c2, 2);
442 p.Controls.Add (c1);
443 p.Controls.Add (c2);
444 p.Controls.Add (c3);
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");
451 [Test]
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 ();
460 p.ColumnCount = 2;
461 p.RowCount = 2;
463 p.SetRowSpan (c3, 2);
465 p.Controls.Add (c1);
466 p.Controls.Add (c2);
467 p.Controls.Add (c3);
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");
474 [Test]
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 ();
483 p.ColumnCount = 2;
484 p.RowCount = 2;
486 p.SetColumn (c1, 4);
488 p.Controls.Add (c1);
489 p.Controls.Add (c2);
490 p.Controls.Add (c3);
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");
497 [Test]
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 ();
506 p.ColumnCount = 3;
507 p.RowCount = 2;
509 p.SetRowSpan (c3, 2);
511 p.Controls.Add (c1);
512 p.Controls.Add (c2);
513 p.Controls.Add (c3);
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");
520 [Test]
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 ();
529 p.ColumnCount = 2;
530 p.RowCount = 2;
532 p.SetColumnSpan (c1, 3);
534 p.Controls.Add (c1);
536 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
539 [Test]
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 ();
549 p.ColumnCount = 2;
550 p.RowCount = 2;
552 p.SetColumnSpan (c2, 2);
553 p.SetCellPosition (c2, new TableLayoutPanelCellPosition (1, 0));
555 p.Controls.Add (c1);
556 p.Controls.Add (c2);
557 p.Controls.Add (c3);
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");
564 [Test]
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 ();
573 p.ColumnCount = 2;
574 p.RowCount = 2;
576 p.SetRowSpan (c3, 2);
577 p.SetCellPosition (c3, new TableLayoutPanelCellPosition (0, 1));
579 p.Controls.Add (c1);
580 p.Controls.Add (c2);
581 p.Controls.Add (c3);
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");
588 [Test]
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 ();
595 p.ColumnCount = 0;
596 p.RowCount = 0;
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");
605 [Test]
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 ();
617 p.ColumnCount = 3;
618 p.RowCount = 4;
620 p.SetRowSpan (c1, 2);
621 p.SetColumnSpan (c1, 2);
622 p.SetCellPosition (c1, new TableLayoutPanelCellPosition (0, 0));
624 p.Controls.Add (c1);
625 p.Controls.Add (c2);
626 p.Controls.Add (c3);
627 p.Controls.Add (c4);
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");
635 [Test]
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 ();
644 p.ColumnCount = 2;
645 p.RowCount = 1;
647 p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
649 p.Controls.Add (c1);
650 p.Controls.Add (c2);
651 p.Controls.Add (c3);
653 Assert.AreEqual (71, p.GetRowHeights ()[0], "D1");
654 Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
657 [Test]
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 ();
666 p.ColumnCount = 2;
667 p.RowCount = 1;
669 p.RowStyles.Add (new RowStyle (SizeType.Absolute, 100F));
671 p.Controls.Add (c1);
672 p.Controls.Add (c2);
673 p.Controls.Add (c3);
675 Assert.AreEqual (100, p.GetRowHeights ()[0], "D1");
676 Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
679 [Test]
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 ();
690 p.ColumnCount = 2;
691 p.RowCount = 1;
693 p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
695 p.Controls.Add (c1);
696 p.Controls.Add (c2);
697 p.Controls.Add (c3);
698 p.Controls.Add (c4);
699 p.Controls.Add (c5);
701 Assert.AreEqual (42, p.GetRowHeights ()[0], "D1");
702 Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
703 Assert.AreEqual (29, p.GetRowHeights ()[2], "D3");
706 [Test]
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 ();
719 p.ColumnCount = 2;
720 p.RowCount = 1;
722 p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
724 p.Controls.Add (c1);
725 p.Controls.Add (c2);
726 p.Controls.Add (c3);
727 p.Controls.Add (c4);
728 p.Controls.Add (c5);
729 p.Controls.Add (c6);
730 p.Controls.Add (c7);
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");
738 [Test]
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 ();
747 p.ColumnCount = 2;
748 p.RowCount = 2;
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));
755 p.Controls.Add (c1);
756 p.Controls.Add (c2);
757 p.Controls.Add (c3);
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");
765 [Test]
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 ();
774 p.ColumnCount = 2;
775 p.RowCount = 2;
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));
782 p.Controls.Add (c1);
783 p.Controls.Add (c2);
784 p.Controls.Add (c3);
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");
792 [Test]
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 ();
801 p.ColumnCount = 3;
802 p.RowCount = 3;
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));
811 p.Controls.Add (c1);
812 p.Controls.Add (c2);
813 p.Controls.Add (c3);
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");
823 [Test]
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 ();
832 p.ColumnCount = 3;
833 p.RowCount = 3;
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));
842 p.Controls.Add (c1);
843 p.Controls.Add (c2);
844 p.Controls.Add (c3);
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");
854 [Test]
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 ();
863 p.ColumnCount = 3;
864 p.RowCount = 3;
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));
873 p.Controls.Add (c1);
874 p.Controls.Add (c2);
875 p.Controls.Add (c3);
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");
885 [Test]
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 ();
894 p.ColumnCount = 2;
895 p.RowCount = 2;
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));
902 p.Controls.Add (c1);
903 p.Controls.Add (c2);
904 p.Controls.Add (c3);
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");
912 [Test]
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);
927 p.ColumnCount = 4;
928 p.RowCount = 3;
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");
956 [Test]
957 public void Bug81843 ()
959 Form f = new Form ();
960 f.ShowInTaskbar = false;
962 TableLayoutPanel tableLayoutPanel1;
963 Button button2;
964 TextBox textBox1;
965 Button button4;
967 tableLayoutPanel1 = new TableLayoutPanel ();
968 button2 = new Button ();
969 button4 = new Button ();
970 textBox1 = new TextBox ();
971 tableLayoutPanel1.SuspendLayout ();
972 f.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);
999 f.Name = "Form1";
1000 f.Text = "Form1";
1001 tableLayoutPanel1.ResumeLayout (false);
1002 tableLayoutPanel1.PerformLayout ();
1003 f.ResumeLayout (false);
1004 f.PerformLayout ();
1006 f.Show ();
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");
1012 f.Dispose ();
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 ();
1023 p.ColumnCount = 3;
1024 p.ColumnStyles.Add (new ColumnStyle ());
1025 p.ColumnStyles.Add (new ColumnStyle ());
1026 p.ColumnStyles.Add (new ColumnStyle ());
1027 p.Dock = DockStyle.Top;
1028 p.Height = 200;
1029 p.RowCount = 2;
1030 p.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
1031 p.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
1032 f.Controls.Add (p);
1034 Label _labelA = new Label ();
1035 _labelA.Dock = DockStyle.Fill;
1036 _labelA.Size = new Size (95, 20);
1037 _labelA.Text = "A";
1038 p.Controls.Add (_labelA, 0, 0);
1040 Label _labelB = new Label ();
1041 _labelB.Dock = DockStyle.Fill;
1042 _labelB.Size = new Size (95, 20);
1043 _labelB.Text = "B";
1044 p.Controls.Add (_labelB, 1, 0);
1046 Label _labelC = new Label ();
1047 _labelC.Dock = DockStyle.Fill;
1048 _labelC.Size = new Size (95, 20);
1049 _labelC.Text = "C";
1050 p.Controls.Add (_labelC, 2, 0);
1052 Label _labelD = new Label ();
1053 _labelD.Dock = DockStyle.Fill;
1054 _labelD.Size = new Size (95, 20);
1055 _labelD.Text = "D";
1056 p.Controls.Add (_labelD, 0, 1);
1058 Label _labelE = new Label ();
1059 _labelE.Dock = DockStyle.Fill;
1060 _labelE.Size = new Size (95, 20);
1061 _labelE.Text = "E";
1062 p.Controls.Add (_labelE, 1, 1);
1064 Label _labelF = new Label ();
1065 _labelF.Dock = DockStyle.Fill;
1066 _labelF.Size = new Size (95, 20);
1067 _labelF.Text = "F";
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;
1077 f.Show ();
1078 // None
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");
1134 f.Close ();
1137 [Test]
1138 public void Bug81936 ()
1140 Form f = new Form ();
1141 f.ShowInTaskbar = false;
1143 TableLayoutPanel tableLayoutPanel1;
1144 Label button2;
1145 Label button4;
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 ();
1157 f.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);
1171 f.Name = "Form1";
1172 f.Text = "Form1";
1173 tableLayoutPanel1.ResumeLayout (false);
1174 tableLayoutPanel1.PerformLayout ();
1175 f.ResumeLayout (false);
1176 f.PerformLayout ();
1178 f.Show ();
1180 Assert.AreEqual (new Rectangle (3, 7, 100, 14), button2.Bounds, "A1");
1181 Assert.AreEqual (new Rectangle (3, 35, 100, 14), button4.Bounds, "A2");
1183 f.Dispose ();
1186 [Test]
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));
1198 table.RowCount = 2;
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);
1204 table.Width = 250;
1206 l.Anchor = AnchorStyles.Left | AnchorStyles.Right;
1207 l.AutoSize = true;
1208 l.Location = new Point (3, 352);
1209 l.Size = new Size (578, 13);
1210 l.Text = "label1";
1211 l.TextAlign = ContentAlignment.MiddleCenter;
1213 f.Controls.Add (table);
1214 f.Show ();
1216 // Height is font dependent, but this bug is about the width anyways
1217 Assert.AreEqual (244, l.Width, "A1");
1219 f.Dispose ();
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);
1234 form.Show ();
1235 form.Refresh ();
1236 form.Dispose ();
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 ());
1253 form.Show ();
1254 form.Refresh ();
1255 form.Dispose ();
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";
1271 tlp.RowCount = 2;
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);
1275 tlp.TabIndex = 0;
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);
1287 f.Show ();
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");
1293 b.Width += 20;
1294 b.Height += 20;
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");
1300 p.Width += 20;
1301 p.Height += 20;
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");
1307 f.Dispose ();
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";
1324 tlp.RowCount = 1;
1325 tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
1326 tlp.Size = new Size (139, 182);
1327 tlp.TabIndex = 0;
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);
1339 f.Show ();
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");
1345 b.Width += 20;
1346 b.Height += 20;
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");
1352 p.Width += 20;
1353 p.Height += 20;
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");
1359 f.Dispose ();
1362 [Test]
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);
1370 tlp.RowCount = 2;
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);
1380 f.Show ();
1382 Assert.AreEqual (new Rectangle (43, 43, 75, 23), b1.Bounds, "A1");
1383 Assert.AreEqual (new Rectangle (43, 72, 75, 23), b2.Bounds, "A2");
1385 f.Close ();
1386 f.Dispose ();
1389 [Test]
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;
1397 tlp.RowCount = 2;
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;
1409 b3.Width = 250;
1410 tlp.SetColumnSpan (b3, 2);
1411 tlp.Controls.Add (b3);
1413 f.Show ();
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");
1419 f.Close ();
1420 f.Dispose ();
1423 [Test]
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;
1431 tlp.RowCount = 2;
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;
1446 b2.Visible = false;
1447 tlp.Controls.Add (b2, 0, 1);
1449 f.Show ();
1451 b2.Visible = true;
1452 Assert.AreEqual (new Size (100, 100), b2.Size, "A1");
1454 b2.Visible = false;
1455 b2.Anchor = AnchorStyles.Left;
1456 b2.Visible = true;
1457 Assert.AreEqual (new Size (100, 100), b2.Size, "A2");
1459 f.Dispose ();
1462 [Test]
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;
1471 tlp.RowCount = 1;
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");
1484 f.Dispose ();
1487 [Test]
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;
1496 tlp.RowCount = 1;
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");
1512 f.Dispose ();
1515 [Test]
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);
1530 [Test]
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;
1545 tlp.RowCount = 0;
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);
1557 f.Show ();
1559 Assert.IsTrue (tlp.Height > 0, "Height must be > 0");
1560 Assert.IsTrue (tlp.Width > 0, "Width must be > 0");
1562 f.Dispose ();
1565 [Test]
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;
1578 tlp.RowCount = 1;
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);
1588 f.Show ();
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");
1596 f.Dispose ();
1599 [Test]
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;
1612 tlp.RowCount = 1;
1614 f.Controls.Add (tlp);
1616 Button t1 = new Button ();
1617 tlp.Controls.Add (t1);
1619 f.Show ();
1621 Assert.AreEqual (29, tlp.Height, "A1");
1623 tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
1625 Assert.AreEqual (29, tlp.Height, "A2");
1627 f.Dispose ();
1630 [Test]
1631 public void TestTableLayoutStyleOwned ()
1633 try {
1634 ColumnStyle style = new ColumnStyle ();
1635 TableLayoutColumnStyleCollection coll = new TableLayoutPanel ().ColumnStyles;
1636 coll.Add (style);
1637 TableLayoutColumnStyleCollection coll2 = new TableLayoutPanel ().ColumnStyles;
1638 coll2.Add (style);
1639 Assert.Fail ("#1");
1640 } catch (ArgumentException ex) {
1641 // PASS
1644 try {
1645 RowStyle style = new RowStyle ();
1646 TableLayoutRowStyleCollection coll = new TableLayoutPanel ().RowStyles;
1647 coll.Add (style);
1648 TableLayoutRowStyleCollection coll2 = new TableLayoutPanel ().RowStyles;
1649 coll2.Add (style);
1650 Assert.Fail ("#2");
1651 } catch (ArgumentException ex) {
1652 // PASS
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);
1666 ms.Position = 0;
1668 tls = (TableLayoutSettings) formatter.Deserialize (ms);
1671 tlp.LayoutSettings = tls;
1672 tlp.LayoutSettings = tls; // Should not throw an exception
1676 [Test]
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));
1693 tlp.RowCount = 1;
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);
1697 tlp.RowCount = 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 ();
1726 #endif