2 // TableLayoutTests.cs
\r
4 // Permission is hereby granted, free of charge, to any person obtaining
\r
5 // a copy of this software and associated documentation files (the
\r
6 // "Software"), to deal in the Software without restriction, including
\r
7 // without limitation the rights to use, copy, modify, merge, publish,
\r
8 // distribute, sublicense, and/or sell copies of the Software, and to
\r
9 // permit persons to whom the Software is furnished to do so, subject to
\r
10 // the following conditions:
\r
12 // The above copyright notice and this permission notice shall be
\r
13 // included in all copies or substantial portions of the Software.
\r
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
\r
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
\r
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
\r
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 // Copyright (c) 2006 Jonathan Pobst
\r
26 // Jonathan Pobst (monkey@jpobst.com)
\r
31 using System.Drawing;
\r
32 using System.Windows.Forms;
\r
33 using NUnit.Framework;
\r
35 namespace MonoTests.System.Windows.Forms
\r
38 public class TableLayoutTests : TestHelper
\r
41 public void TestConstruction ()
\r
43 TableLayoutPanel p = new TableLayoutPanel ();
\r
45 Assert.AreEqual (BorderStyle.None, p.BorderStyle, "A1");
\r
46 Assert.AreEqual (TableLayoutPanelCellBorderStyle.None, p.CellBorderStyle, "A2");
\r
47 Assert.AreEqual (0, p.ColumnCount, "A3");
\r
48 Assert.AreEqual (TableLayoutPanelGrowStyle.AddRows, p.GrowStyle, "A4");
\r
49 Assert.AreEqual ("System.Windows.Forms.Layout.TableLayout", p.LayoutEngine.ToString (), "A5");
\r
50 Assert.AreEqual ("System.Windows.Forms.TableLayoutSettings", p.LayoutSettings.ToString (), "A6");
\r
51 Assert.AreEqual (0, p.RowCount, "A7");
\r
52 Assert.AreEqual (0, p.ColumnStyles.Count, "A8");
\r
53 Assert.AreEqual (0, p.RowStyles.Count, "A9");
\r
54 Assert.AreEqual (new Size (200, 100), p.Size, "A10");
\r
58 public void TestPropertySetters ()
\r
60 TableLayoutPanel p = new TableLayoutPanel ();
\r
62 p.BorderStyle = BorderStyle.Fixed3D;
\r
63 p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;
\r
65 p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;
\r
68 Assert.AreEqual (BorderStyle.Fixed3D, p.BorderStyle, "A1");
\r
69 Assert.AreEqual (TableLayoutPanelCellBorderStyle.OutsetDouble, p.CellBorderStyle, "A2");
\r
70 Assert.AreEqual (1, p.ColumnCount, "A3");
\r
71 Assert.AreEqual (TableLayoutPanelGrowStyle.FixedSize, p.GrowStyle, "A4");
\r
72 Assert.AreEqual (1, p.RowCount, "A7");
\r
76 public void TestExtenderMethods ()
\r
78 TableLayoutPanel p = new TableLayoutPanel ();
\r
79 Control c = new Button ();
\r
81 Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetCellPosition (c), "A1");
\r
82 Assert.AreEqual (-1, p.GetColumn (c), "A2");
\r
83 Assert.AreEqual (1, p.GetColumnSpan (c), "A3");
\r
84 Assert.AreEqual (-1, p.GetRow (c), "A4");
\r
85 Assert.AreEqual (1, p.GetRowSpan (c), "A5");
\r
87 p.SetCellPosition (c, new TableLayoutPanelCellPosition (1, 1));
\r
88 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetCellPosition (c), "A6");
\r
91 Assert.AreEqual (2, p.GetColumn (c), "A7");
\r
93 Assert.AreEqual (2, p.GetRow (c), "A9");
\r
95 p.SetColumnSpan (c, 2);
\r
96 Assert.AreEqual (2, p.GetColumnSpan (c), "A8");
\r
99 p.SetRowSpan (c, 2);
\r
100 Assert.AreEqual (2, p.GetRowSpan (c), "A10");
\r
102 Assert.AreEqual (new TableLayoutPanelCellPosition (2, 2), p.GetCellPosition (c), "A11");
\r
105 //Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetPositionFromControl (c), "A12");
\r
106 //Assert.AreEqual (c, p.GetControlFromPosition(0, 0), "A13");
\r
110 public void TestColumnStyles ()
\r
112 TableLayoutPanel p = new TableLayoutPanel ();
\r
114 p.ColumnStyles.Add (new ColumnStyle ());
\r
115 p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute));
\r
116 p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 20F));
\r
118 Assert.AreEqual (3, p.ColumnStyles.Count, "A1");
\r
119 Assert.AreEqual (SizeType.AutoSize, p.ColumnStyles[0].SizeType, "A2");
\r
120 Assert.AreEqual (0, p.ColumnStyles[0].Width, "A3");
\r
121 Assert.AreEqual (SizeType.Absolute, p.ColumnStyles[1].SizeType, "A4");
\r
122 Assert.AreEqual (0, p.ColumnStyles[1].Width, "A5");
\r
123 Assert.AreEqual (SizeType.Percent, p.ColumnStyles[2].SizeType, "A6");
\r
124 Assert.AreEqual (20F, p.ColumnStyles[2].Width, "A7");
\r
126 p.ColumnStyles.Remove (p.ColumnStyles[0]);
\r
128 Assert.AreEqual (2, p.ColumnStyles.Count, "A8");
\r
129 Assert.AreEqual (SizeType.Absolute, p.ColumnStyles[0].SizeType, "A9");
\r
130 Assert.AreEqual (0, p.ColumnStyles[0].Width, "A10");
\r
131 Assert.AreEqual (SizeType.Percent, p.ColumnStyles[1].SizeType, "A11");
\r
132 Assert.AreEqual (20F, p.ColumnStyles[1].Width, "A12");
\r
136 public void TestRowStyles ()
\r
138 TableLayoutPanel p = new TableLayoutPanel ();
\r
140 p.RowStyles.Add (new RowStyle ());
\r
141 p.RowStyles.Add (new RowStyle (SizeType.Absolute));
\r
142 p.RowStyles.Add (new RowStyle (SizeType.Percent, 20F));
\r
144 Assert.AreEqual (3, p.RowStyles.Count, "A1");
\r
145 Assert.AreEqual (SizeType.AutoSize, p.RowStyles[0].SizeType, "A2");
\r
146 Assert.AreEqual (0, p.RowStyles[0].Height, "A3");
\r
147 Assert.AreEqual (SizeType.Absolute, p.RowStyles[1].SizeType, "A4");
\r
148 Assert.AreEqual (0, p.RowStyles[1].Height, "A5");
\r
149 Assert.AreEqual (SizeType.Percent, p.RowStyles[2].SizeType, "A6");
\r
150 Assert.AreEqual (20F, p.RowStyles[2].Height, "A7");
\r
152 p.RowStyles.Remove (p.RowStyles[0]);
\r
154 Assert.AreEqual (2, p.RowStyles.Count, "A8");
\r
155 Assert.AreEqual (SizeType.Absolute, p.RowStyles[0].SizeType, "A9");
\r
156 Assert.AreEqual (0, p.RowStyles[0].Height, "A10");
\r
157 Assert.AreEqual (SizeType.Percent, p.RowStyles[1].SizeType, "A11");
\r
158 Assert.AreEqual (20F, p.RowStyles[1].Height, "A12");
\r
162 public void TestColumnStyles3 ()
\r
164 // Don't lose the 2nd style
\r
165 TableLayoutPanel p = new TableLayoutPanel ();
\r
168 p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));
\r
169 p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));
\r
173 Assert.AreEqual (2, p.ColumnStyles.Count, "A1");
\r
177 public void TestColumnStyles2 ()
\r
179 // Don't lose the 2nd style
\r
180 TableLayoutPanel p = new TableLayoutPanel ();
\r
183 p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));
\r
187 Assert.AreEqual (1, p.ColumnStyles.Count, "A2");
\r
191 public void TestCellPositioning ()
\r
194 TableLayoutPanel p = new TableLayoutPanel ();
\r
195 Control c1 = new Button ();
\r
196 Control c2 = new Button ();
\r
197 Control c3 = new Button ();
\r
198 Control c4 = new Button ();
\r
203 p.Controls.Add (c1);
\r
204 p.Controls.Add (c2);
\r
205 p.Controls.Add (c3);
\r
206 p.Controls.Add (c4);
\r
208 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
209 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
\r
210 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
\r
211 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c4), "C4");
\r
215 public void TestCellPositioning2 ()
\r
217 // Growstyle = Add Rows
\r
218 TableLayoutPanel p = new TableLayoutPanel ();
\r
219 Control c1 = new Button ();
\r
220 Control c2 = new Button ();
\r
221 Control c3 = new Button ();
\r
222 Control c4 = new Button ();
\r
223 Control c5 = new Button ();
\r
224 Control c6 = new Button ();
\r
229 p.Controls.Add (c1);
\r
230 p.Controls.Add (c2);
\r
231 p.Controls.Add (c3);
\r
232 p.Controls.Add (c4);
\r
233 p.Controls.Add (c5);
\r
234 p.Controls.Add (c6);
\r
236 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
237 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
\r
238 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
\r
239 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c4), "C4");
\r
240 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 2), p.GetPositionFromControl (c5), "C5");
\r
241 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 2), p.GetPositionFromControl (c6), "C6");
\r
245 public void TestCellPositioning3 ()
\r
247 // Growstyle = Add Columns
\r
248 TableLayoutPanel p = new TableLayoutPanel ();
\r
249 p.GrowStyle = TableLayoutPanelGrowStyle.AddColumns;
\r
251 Control c1 = new Button ();
\r
252 Control c2 = new Button ();
\r
253 Control c3 = new Button ();
\r
254 Control c4 = new Button ();
\r
255 Control c5 = new Button ();
\r
256 Control c6 = new Button ();
\r
261 p.Controls.Add (c1);
\r
262 p.Controls.Add (c2);
\r
263 p.Controls.Add (c3);
\r
264 p.Controls.Add (c4);
\r
265 p.Controls.Add (c5);
\r
266 p.Controls.Add (c6);
\r
268 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
269 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
\r
270 Assert.AreEqual (new TableLayoutPanelCellPosition (2, 0), p.GetPositionFromControl (c3), "C3");
\r
271 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c4), "C4");
\r
272 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c5), "C5");
\r
273 Assert.AreEqual (new TableLayoutPanelCellPosition (2, 1), p.GetPositionFromControl (c6), "C6");
\r
277 [ExpectedException (typeof (ArgumentException))]
\r
278 public void TestCellPositioning4 ()
\r
280 // Growstyle = Fixed Size
\r
281 TableLayoutPanel p = new TableLayoutPanel ();
\r
282 p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;
\r
284 Control c1 = new Button ();
\r
285 Control c2 = new Button ();
\r
286 Control c3 = new Button ();
\r
287 Control c4 = new Button ();
\r
288 Control c5 = new Button ();
\r
293 p.Controls.Add (c1);
\r
294 p.Controls.Add (c2);
\r
295 p.Controls.Add (c3);
\r
296 p.Controls.Add (c4);
\r
297 p.Controls.Add (c5);
\r
301 public void TestCellPositioning5 ()
\r
303 // One control have fixed position
\r
304 TableLayoutPanel p = new TableLayoutPanel ();
\r
305 Control c1 = new Button ();
\r
306 Control c2 = new Button ();
\r
307 Control c3 = new Button ();
\r
308 Control c4 = new Button ();
\r
313 p.SetCellPosition (c4, new TableLayoutPanelCellPosition (0, 0));
\r
315 p.Controls.Add (c1);
\r
316 p.Controls.Add (c2);
\r
317 p.Controls.Add (c3);
\r
318 p.Controls.Add (c4);
\r
320 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c4), "C1");
\r
321 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c1), "C2");
\r
322 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c2), "C3");
\r
323 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c3), "C4");
\r
327 public void TestCellPositioning6 ()
\r
329 // One control has fixed column, it should be ignored
\r
330 TableLayoutPanel p = new TableLayoutPanel ();
\r
331 Control c1 = new Button ();
\r
332 Control c2 = new Button ();
\r
333 Control c3 = new Button ();
\r
334 Control c4 = new Button ();
\r
339 p.SetColumn (c3, 1);
\r
341 p.Controls.Add (c1);
\r
342 p.Controls.Add (c2);
\r
343 p.Controls.Add (c3);
\r
344 p.Controls.Add (c4);
\r
346 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
347 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
\r
348 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
\r
349 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c4), "C4");
\r
353 public void TestCellPositioning7 ()
\r
355 // One control has fixed column and row
\r
356 TableLayoutPanel p = new TableLayoutPanel ();
\r
357 Control c1 = new Button ();
\r
358 Control c2 = new Button ();
\r
359 Control c3 = new Button ();
\r
360 Control c4 = new Button ();
\r
365 p.SetColumn (c3, 1);
\r
368 p.Controls.Add (c1);
\r
369 p.Controls.Add (c2);
\r
370 p.Controls.Add (c3);
\r
371 p.Controls.Add (c4);
\r
373 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
374 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
\r
375 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c3), "C3");
\r
376 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c4), "C4");
\r
380 public void TestCellPositioning8 ()
\r
383 TableLayoutPanel p = new TableLayoutPanel ();
\r
384 Control c1 = new Button ();
\r
385 Control c2 = new Button ();
\r
386 Control c3 = new Button ();
\r
391 p.SetColumnSpan (c1, 2);
\r
393 p.Controls.Add (c1);
\r
394 p.Controls.Add (c2);
\r
395 p.Controls.Add (c3);
\r
397 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
398 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c2), "C2");
\r
399 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c3), "C3");
\r
403 public void TestCellPositioning9 ()
\r
406 TableLayoutPanel p = new TableLayoutPanel ();
\r
407 Control c1 = new Button ();
\r
408 Control c2 = new Button ();
\r
409 Control c3 = new Button ();
\r
414 p.SetRowSpan (c1, 2);
\r
416 p.Controls.Add (c1);
\r
417 p.Controls.Add (c2);
\r
418 p.Controls.Add (c3);
\r
420 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
421 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
\r
422 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c3), "C3");
\r
426 public void TestCellPositioning10 ()
\r
428 // Column span = 2, but control is in the last column, forces control back into 1st column, next row
\r
429 // I have no clue why c3 shouldn't be in (1,0), but MS says it's not
\r
430 TableLayoutPanel p = new TableLayoutPanel ();
\r
431 Control c1 = new Button ();
\r
432 Control c2 = new Button ();
\r
433 Control c3 = new Button ();
\r
438 p.SetColumnSpan (c2, 2);
\r
440 p.Controls.Add (c1);
\r
441 p.Controls.Add (c2);
\r
442 p.Controls.Add (c3);
\r
444 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
445 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c2), "C2");
\r
446 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 2), p.GetPositionFromControl (c3), "C3");
\r
450 public void TestCellPositioning11 ()
\r
452 // Row span = 2, but control is in the last row, creates new row
\r
453 TableLayoutPanel p = new TableLayoutPanel ();
\r
454 Control c1 = new Button ();
\r
455 Control c2 = new Button ();
\r
456 Control c3 = new Button ();
\r
461 p.SetRowSpan (c3, 2);
\r
463 p.Controls.Add (c1);
\r
464 p.Controls.Add (c2);
\r
465 p.Controls.Add (c3);
\r
467 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
468 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
\r
469 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
\r
473 public void TestCellPositioning12 ()
\r
475 // Requesting a column greater than ColumnCount, request is ignored
\r
476 TableLayoutPanel p = new TableLayoutPanel ();
\r
477 Control c1 = new Button ();
\r
478 Control c2 = new Button ();
\r
479 Control c3 = new Button ();
\r
484 p.SetColumn (c1, 4);
\r
486 p.Controls.Add (c1);
\r
487 p.Controls.Add (c2);
\r
488 p.Controls.Add (c3);
\r
490 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
491 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
\r
492 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
\r
496 public void TestCellPositioning13 ()
\r
498 // Row span = 2, but control is in the last row, creates new row
\r
499 TableLayoutPanel p = new TableLayoutPanel ();
\r
500 Control c1 = new Button ();
\r
501 Control c2 = new Button ();
\r
502 Control c3 = new Button ();
\r
507 p.SetRowSpan (c3, 2);
\r
509 p.Controls.Add (c1);
\r
510 p.Controls.Add (c2);
\r
511 p.Controls.Add (c3);
\r
513 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
514 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
\r
515 Assert.AreEqual (new TableLayoutPanelCellPosition (2, 0), p.GetPositionFromControl (c3), "C3");
\r
519 [Category ("NotWorking")]
\r
520 public void TestCellPositioning14 ()
\r
522 // Col span = 3, fixed grow style
\r
523 TableLayoutPanel p = new TableLayoutPanel ();
\r
524 p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;
\r
525 Control c1 = new Button ();
\r
530 p.SetColumnSpan (c1, 3);
\r
532 p.Controls.Add (c1);
\r
534 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
538 public void TestCellPositioning15 ()
\r
540 // Column span = 2, but control is in the last column, forces control back into 1st column, next row
\r
541 // I have no clue why c3 shouldn't be in (1,0), but MS says it's not
\r
542 TableLayoutPanel p = new TableLayoutPanel ();
\r
543 Control c1 = new Button ();
\r
544 Control c2 = new Button ();
\r
545 Control c3 = new Button ();
\r
550 p.SetColumnSpan (c2, 2);
\r
551 p.SetCellPosition (c2, new TableLayoutPanelCellPosition (1, 0));
\r
553 p.Controls.Add (c1);
\r
554 p.Controls.Add (c2);
\r
555 p.Controls.Add (c3);
\r
557 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
558 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c2), "C2");
\r
559 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 2), p.GetPositionFromControl (c3), "C3");
\r
563 public void TestCellPositioning16 ()
\r
565 // Row span = 2, but control is in the last row, creates new row
\r
566 TableLayoutPanel p = new TableLayoutPanel ();
\r
567 Control c1 = new Button ();
\r
568 Control c2 = new Button ();
\r
569 Control c3 = new Button ();
\r
574 p.SetRowSpan (c3, 2);
\r
575 p.SetCellPosition (c3, new TableLayoutPanelCellPosition (0, 1));
\r
577 p.Controls.Add (c1);
\r
578 p.Controls.Add (c2);
\r
579 p.Controls.Add (c3);
\r
581 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
582 Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
\r
583 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
\r
587 public void TestCellPositioning17 ()
\r
589 // ColumnCount == RowCount == 0, but control is added at > 0.
\r
590 // The columns and rows are created, but ColumnCount and RowCount remains 0
\r
592 TableLayoutPanel p = new TableLayoutPanel ();
\r
595 Control c1 = new Button ();
\r
597 p.Controls.Add (c1, 6, 7);
\r
598 Assert.AreEqual (new TableLayoutPanelCellPosition (6, 7), p.GetPositionFromControl (c1), "C1");
\r
599 Assert.AreEqual (0, p.LayoutSettings.ColumnCount, "C2");
\r
600 Assert.AreEqual (0, p.LayoutSettings.RowCount, "C3");
\r
604 public void TestCellPositioning18 ()
\r
606 // A control with both rowspan and columnspan > 1 was getting
\r
607 // other controls put into its extent (i.e. c3 was ending up
\r
608 // at (1,1) instead of (2,1).
\r
609 TableLayoutPanel p = new TableLayoutPanel ();
\r
610 Control c1 = new Button ();
\r
611 Control c2 = new Button ();
\r
612 Control c3 = new Button ();
\r
613 Control c4 = new Button ();
\r
618 p.SetRowSpan (c1, 2);
\r
619 p.SetColumnSpan (c1, 2);
\r
620 p.SetCellPosition (c1, new TableLayoutPanelCellPosition (0, 0));
\r
622 p.Controls.Add (c1);
\r
623 p.Controls.Add (c2);
\r
624 p.Controls.Add (c3);
\r
625 p.Controls.Add (c4);
\r
627 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
\r
628 Assert.AreEqual (new TableLayoutPanelCellPosition (2, 0), p.GetPositionFromControl (c2), "C2");
\r
629 Assert.AreEqual (new TableLayoutPanelCellPosition (2, 1), p.GetPositionFromControl (c3), "C3");
\r
630 Assert.AreEqual (new TableLayoutPanelCellPosition (0, 2), p.GetPositionFromControl (c4), "C4");
\r
634 public void TestRowColumnSizes1 ()
\r
636 // Row span = 2, but control is in the last row, creates new row
\r
637 TableLayoutPanel p = new TableLayoutPanel ();
\r
638 Control c1 = new Button ();
\r
639 Control c2 = new Button ();
\r
640 Control c3 = new Button ();
\r
645 p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
\r
647 p.Controls.Add (c1);
\r
648 p.Controls.Add (c2);
\r
649 p.Controls.Add (c3);
\r
651 Assert.AreEqual (71, p.GetRowHeights ()[0], "D1");
\r
652 Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
\r
656 public void TestRowColumnSizes2 ()
\r
658 // Row span = 2, but control is in the last row, creates new row
\r
659 TableLayoutPanel p = new TableLayoutPanel ();
\r
660 Control c1 = new Button ();
\r
661 Control c2 = new Button ();
\r
662 Control c3 = new Button ();
\r
667 p.RowStyles.Add (new RowStyle (SizeType.Absolute, 100F));
\r
669 p.Controls.Add (c1);
\r
670 p.Controls.Add (c2);
\r
671 p.Controls.Add (c3);
\r
673 Assert.AreEqual (100, p.GetRowHeights ()[0], "D1");
\r
674 Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
\r
678 public void TestRowColumnSizes3 ()
\r
680 // Row span = 2, but control is in the last row, creates new row
\r
681 TableLayoutPanel p = new TableLayoutPanel ();
\r
682 Control c1 = new Button ();
\r
683 Control c2 = new Button ();
\r
684 Control c3 = new Button ();
\r
685 Control c4 = new Button ();
\r
686 Control c5 = new Button ();
\r
691 p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
\r
693 p.Controls.Add (c1);
\r
694 p.Controls.Add (c2);
\r
695 p.Controls.Add (c3);
\r
696 p.Controls.Add (c4);
\r
697 p.Controls.Add (c5);
\r
699 Assert.AreEqual (42, p.GetRowHeights ()[0], "D1");
\r
700 Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
\r
701 Assert.AreEqual (29, p.GetRowHeights ()[2], "D3");
\r
705 public void TestRowColumnSizes4 ()
\r
707 // Row span = 2, but control is in the last row, creates new row
\r
708 TableLayoutPanel p = new TableLayoutPanel ();
\r
709 Control c1 = new Button ();
\r
710 Control c2 = new Button ();
\r
711 Control c3 = new Button ();
\r
712 Control c4 = new Button ();
\r
713 Control c5 = new Button ();
\r
714 Control c6 = new Button ();
\r
715 Control c7 = new Button ();
\r
720 p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
\r
722 p.Controls.Add (c1);
\r
723 p.Controls.Add (c2);
\r
724 p.Controls.Add (c3);
\r
725 p.Controls.Add (c4);
\r
726 p.Controls.Add (c5);
\r
727 p.Controls.Add (c6);
\r
728 p.Controls.Add (c7);
\r
730 //Assert.AreEqual (100, p.GetRowHeights ()[0], "D1");
\r
731 Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
\r
732 Assert.AreEqual (29, p.GetRowHeights ()[2], "D3");
\r
733 Assert.AreEqual (29, p.GetRowHeights ()[3], "D4");
\r
737 public void TestRowColumnSizes5 ()
\r
739 // 2 Absolute Columns/Rows
\r
740 TableLayoutPanel p = new TableLayoutPanel ();
\r
741 Control c1 = new Button ();
\r
742 Control c2 = new Button ();
\r
743 Control c3 = new Button ();
\r
748 p.RowStyles.Add (new RowStyle (SizeType.Absolute, 20));
\r
749 p.RowStyles.Add (new RowStyle (SizeType.Absolute, 30));
\r
750 p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20));
\r
751 p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 30));
\r
753 p.Controls.Add (c1);
\r
754 p.Controls.Add (c2);
\r
755 p.Controls.Add (c3);
\r
757 Assert.AreEqual (20, p.GetRowHeights ()[0], "D1");
\r
758 Assert.AreEqual (80, p.GetRowHeights ()[1], "D2");
\r
759 Assert.AreEqual (20, p.GetColumnWidths ()[0], "D3");
\r
760 Assert.AreEqual (180, p.GetColumnWidths ()[1], "D4");
\r
764 public void TestRowColumnSizes6 ()
\r
766 // 2 50% Columns/Rows
\r
767 TableLayoutPanel p = new TableLayoutPanel ();
\r
768 Control c1 = new Button ();
\r
769 Control c2 = new Button ();
\r
770 Control c3 = new Button ();
\r
775 p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
\r
776 p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
\r
777 p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
\r
778 p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
\r
780 p.Controls.Add (c1);
\r
781 p.Controls.Add (c2);
\r
782 p.Controls.Add (c3);
\r
784 Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
\r
785 Assert.AreEqual (50, p.GetRowHeights ()[1], "D2");
\r
786 Assert.AreEqual (100, p.GetColumnWidths ()[0], "D3");
\r
787 Assert.AreEqual (100, p.GetColumnWidths ()[1], "D4");
\r
791 public void TestRowColumnSizes7 ()
\r
793 // 1 Absolute and 2 Percent Columns/Rows
\r
794 TableLayoutPanel p = new TableLayoutPanel ();
\r
795 Control c1 = new Button ();
\r
796 Control c2 = new Button ();
\r
797 Control c3 = new Button ();
\r
802 p.RowStyles.Add (new RowStyle (SizeType.Absolute, 50));
\r
803 p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
\r
804 p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
\r
805 p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 50));
\r
806 p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
\r
807 p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
\r
809 p.Controls.Add (c1);
\r
810 p.Controls.Add (c2);
\r
811 p.Controls.Add (c3);
\r
813 Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
\r
814 Assert.AreEqual (25, p.GetRowHeights ()[1], "D2");
\r
815 Assert.AreEqual (25, p.GetRowHeights ()[2], "D3");
\r
816 Assert.AreEqual (50, p.GetColumnWidths ()[0], "D4");
\r
817 Assert.AreEqual (75, p.GetColumnWidths ()[1], "D5");
\r
818 Assert.AreEqual (75, p.GetColumnWidths ()[2], "D6");
\r
822 public void TestRowColumnSizes8 ()
\r
824 // 1 Absolute and 2 Percent Columns/Rows (with total percents > 100)
\r
825 TableLayoutPanel p = new TableLayoutPanel ();
\r
826 Control c1 = new Button ();
\r
827 Control c2 = new Button ();
\r
828 Control c3 = new Button ();
\r
833 p.RowStyles.Add (new RowStyle (SizeType.Absolute, 50));
\r
834 p.RowStyles.Add (new RowStyle (SizeType.Percent, 100));
\r
835 p.RowStyles.Add (new RowStyle (SizeType.Percent, 100));
\r
836 p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 50));
\r
837 p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100));
\r
838 p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100));
\r
840 p.Controls.Add (c1);
\r
841 p.Controls.Add (c2);
\r
842 p.Controls.Add (c3);
\r
844 Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
\r
845 Assert.AreEqual (25, p.GetRowHeights ()[1], "D2");
\r
846 Assert.AreEqual (25, p.GetRowHeights ()[2], "D3");
\r
847 Assert.AreEqual (50, p.GetColumnWidths ()[0], "D4");
\r
848 Assert.AreEqual (75, p.GetColumnWidths ()[1], "D5");
\r
849 Assert.AreEqual (75, p.GetColumnWidths ()[2], "D6");
\r
853 public void TestRowColumnSizes9 ()
\r
855 // 1 Absolute and 2 Percent Columns/Rows (with total percents > 100)
\r
856 TableLayoutPanel p = new TableLayoutPanel ();
\r
857 Control c1 = new Button ();
\r
858 Control c2 = new Button ();
\r
859 Control c3 = new Button ();
\r
864 p.RowStyles.Add (new RowStyle (SizeType.Absolute, 50));
\r
865 p.RowStyles.Add (new RowStyle (SizeType.Percent, 80));
\r
866 p.RowStyles.Add (new RowStyle (SizeType.Percent, 40));
\r
867 p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 50));
\r
868 p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 80));
\r
869 p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 40));
\r
871 p.Controls.Add (c1);
\r
872 p.Controls.Add (c2);
\r
873 p.Controls.Add (c3);
\r
875 Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
\r
876 Assert.AreEqual (33, p.GetRowHeights ()[1], "D2");
\r
877 Assert.AreEqual (17, p.GetRowHeights ()[2], "D3");
\r
878 Assert.AreEqual (50, p.GetColumnWidths ()[0], "D4");
\r
879 Assert.AreEqual (100, p.GetColumnWidths ()[1], "D5");
\r
880 Assert.AreEqual (50, p.GetColumnWidths ()[2], "D6");
\r
884 public void TestRowColumnSizes10 ()
\r
886 // 2 AutoSize Columns/Rows
\r
887 TableLayoutPanel p = new TableLayoutPanel ();
\r
888 Control c1 = new Button ();
\r
889 Control c2 = new Button ();
\r
890 Control c3 = new Button ();
\r
895 p.RowStyles.Add (new RowStyle (SizeType.AutoSize));
\r
896 p.RowStyles.Add (new RowStyle (SizeType.AutoSize));
\r
897 p.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
\r
898 p.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
\r
900 p.Controls.Add (c1);
\r
901 p.Controls.Add (c2);
\r
902 p.Controls.Add (c3);
\r
904 Assert.AreEqual (29, p.GetRowHeights ()[0], "D1");
\r
905 Assert.AreEqual (71, p.GetRowHeights ()[1], "D2");
\r
906 Assert.AreEqual (81, p.GetColumnWidths ()[0], "D3");
\r
907 Assert.AreEqual (119, p.GetColumnWidths ()[1], "D4");
\r
911 public void Bug81843 ()
\r
913 Form f = new Form ();
\r
914 f.ShowInTaskbar = false;
\r
916 TableLayoutPanel tableLayoutPanel1;
\r
921 tableLayoutPanel1 = new TableLayoutPanel ();
\r
922 button2 = new Button ();
\r
923 button4 = new Button ();
\r
924 textBox1 = new TextBox ();
\r
925 tableLayoutPanel1.SuspendLayout ();
\r
926 f.SuspendLayout ();
\r
928 tableLayoutPanel1.AutoSize = true;
\r
929 tableLayoutPanel1.ColumnCount = 3;
\r
930 tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
\r
931 tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
\r
932 tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
\r
933 tableLayoutPanel1.Controls.Add (button2, 0, 1);
\r
934 tableLayoutPanel1.Controls.Add (button4, 2, 1);
\r
935 tableLayoutPanel1.Controls.Add (textBox1, 1, 0);
\r
936 tableLayoutPanel1.Location = new Point (0, 0);
\r
937 tableLayoutPanel1.RowCount = 2;
\r
938 tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
\r
939 tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
\r
940 tableLayoutPanel1.Size = new Size (292, 287);
\r
942 button2.Size = new Size (75, 23);
\r
944 button4.Size = new Size (75, 23);
\r
946 textBox1.Dock = DockStyle.Fill;
\r
947 textBox1.Location = new Point (84, 3);
\r
948 textBox1.Multiline = true;
\r
949 textBox1.Size = new Size (94, 137);
\r
951 f.ClientSize = new Size (292, 312);
\r
952 f.Controls.Add (tableLayoutPanel1);
\r
955 tableLayoutPanel1.ResumeLayout (false);
\r
956 tableLayoutPanel1.PerformLayout ();
\r
957 f.ResumeLayout (false);
\r
958 f.PerformLayout ();
\r
962 Assert.AreEqual (new Rectangle (3, 146, 75, 23), button2.Bounds, "A1");
\r
963 Assert.AreEqual (new Rectangle (184, 146, 75, 23), button4.Bounds, "A2");
\r
964 Assert.AreEqual (new Rectangle (84, 3, 94, 137), textBox1.Bounds, "A3");
\r
969 [Test] // From bug #81884
\r
970 public void CellBorderStyle ()
\r
972 Form f = new Form ();
\r
973 f.ShowInTaskbar = false;
\r
975 TableLayoutPanel p = new TableLayoutPanel ();
\r
976 p = new TableLayoutPanel ();
\r
978 p.ColumnStyles.Add (new ColumnStyle ());
\r
979 p.ColumnStyles.Add (new ColumnStyle ());
\r
980 p.ColumnStyles.Add (new ColumnStyle ());
\r
981 p.Dock = DockStyle.Top;
\r
984 p.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
\r
985 p.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
\r
986 f.Controls.Add (p);
\r
988 Label _labelA = new Label ();
\r
989 _labelA.Dock = DockStyle.Fill;
\r
990 _labelA.Size = new Size (95, 20);
\r
991 _labelA.Text = "A";
\r
992 p.Controls.Add (_labelA, 0, 0);
\r
994 Label _labelB = new Label ();
\r
995 _labelB.Dock = DockStyle.Fill;
\r
996 _labelB.Size = new Size (95, 20);
\r
997 _labelB.Text = "B";
\r
998 p.Controls.Add (_labelB, 1, 0);
\r
1000 Label _labelC = new Label ();
\r
1001 _labelC.Dock = DockStyle.Fill;
\r
1002 _labelC.Size = new Size (95, 20);
\r
1003 _labelC.Text = "C";
\r
1004 p.Controls.Add (_labelC, 2, 0);
\r
1006 Label _labelD = new Label ();
\r
1007 _labelD.Dock = DockStyle.Fill;
\r
1008 _labelD.Size = new Size (95, 20);
\r
1009 _labelD.Text = "D";
\r
1010 p.Controls.Add (_labelD, 0, 1);
\r
1012 Label _labelE = new Label ();
\r
1013 _labelE.Dock = DockStyle.Fill;
\r
1014 _labelE.Size = new Size (95, 20);
\r
1015 _labelE.Text = "E";
\r
1016 p.Controls.Add (_labelE, 1, 1);
\r
1018 Label _labelF = new Label ();
\r
1019 _labelF.Dock = DockStyle.Fill;
\r
1020 _labelF.Size = new Size (95, 20);
\r
1021 _labelF.Text = "F";
\r
1022 p.Controls.Add (_labelF, 2, 1);
\r
1024 _labelA.BackColor = Color.Red;
\r
1025 _labelB.BackColor = Color.Orange;
\r
1026 _labelC.BackColor = Color.Yellow;
\r
1027 _labelD.BackColor = Color.Green;
\r
1028 _labelE.BackColor = Color.Blue;
\r
1029 _labelF.BackColor = Color.Purple;
\r
1033 Assert.AreEqual (new Rectangle (3, 0, 95, 100), _labelA.Bounds, "A1");
\r
1034 Assert.AreEqual (new Rectangle (104, 0, 95, 100), _labelB.Bounds, "A2");
\r
1035 Assert.AreEqual (new Rectangle (205, 0, 95, 100), _labelC.Bounds, "A3");
\r
1036 Assert.AreEqual (new Rectangle (3, 100, 95, 100), _labelD.Bounds, "A4");
\r
1037 Assert.AreEqual (new Rectangle (104, 100, 95, 100), _labelE.Bounds, "A5");
\r
1038 Assert.AreEqual (new Rectangle (205, 100, 95, 100), _labelF.Bounds, "A6");
\r
1040 p.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
\r
1041 Assert.AreEqual (new Rectangle (4, 1, 95, 98), _labelA.Bounds, "A7");
\r
1042 Assert.AreEqual (new Rectangle (106, 1, 95, 98), _labelB.Bounds, "A8");
\r
1043 Assert.AreEqual (new Rectangle (208, 1, 95, 98), _labelC.Bounds, "A9");
\r
1044 Assert.AreEqual (new Rectangle (4, 100, 95, 99), _labelD.Bounds, "A10");
\r
1045 Assert.AreEqual (new Rectangle (106, 100, 95, 99), _labelE.Bounds, "A11");
\r
1046 Assert.AreEqual (new Rectangle (208, 100, 95, 99), _labelF.Bounds, "A12");
\r
1048 p.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
\r
1049 Assert.AreEqual (new Rectangle (5, 2, 95, 97), _labelA.Bounds, "A13");
\r
1050 Assert.AreEqual (new Rectangle (108, 2, 95, 97), _labelB.Bounds, "A14");
\r
1051 Assert.AreEqual (new Rectangle (211, 2, 95, 97), _labelC.Bounds, "A15");
\r
1052 Assert.AreEqual (new Rectangle (5, 101, 95, 97), _labelD.Bounds, "A16");
\r
1053 Assert.AreEqual (new Rectangle (108, 101, 95, 97), _labelE.Bounds, "A17");
\r
1054 Assert.AreEqual (new Rectangle (211, 101, 95, 97), _labelF.Bounds, "A18");
\r
1056 p.CellBorderStyle = TableLayoutPanelCellBorderStyle.InsetDouble;
\r
1057 Assert.AreEqual (new Rectangle (6, 3, 95, 95), _labelA.Bounds, "A19");
\r
1058 Assert.AreEqual (new Rectangle (110, 3, 95, 95), _labelB.Bounds, "A20");
\r
1059 Assert.AreEqual (new Rectangle (214, 3, 95, 95), _labelC.Bounds, "A21");
\r
1060 Assert.AreEqual (new Rectangle (6, 101, 95, 96), _labelD.Bounds, "A22");
\r
1061 Assert.AreEqual (new Rectangle (110, 101, 95, 96), _labelE.Bounds, "A23");
\r
1062 Assert.AreEqual (new Rectangle (214, 101, 95, 96), _labelF.Bounds, "A24");
\r
1064 p.CellBorderStyle = TableLayoutPanelCellBorderStyle.Outset;
\r
1065 Assert.AreEqual (new Rectangle (5, 2, 95, 97), _labelA.Bounds, "A25");
\r
1066 Assert.AreEqual (new Rectangle (108, 2, 95, 97), _labelB.Bounds, "A26");
\r
1067 Assert.AreEqual (new Rectangle (211, 2, 95, 97), _labelC.Bounds, "A27");
\r
1068 Assert.AreEqual (new Rectangle (5, 101, 95, 97), _labelD.Bounds, "A28");
\r
1069 Assert.AreEqual (new Rectangle (108, 101, 95, 97), _labelE.Bounds, "A29");
\r
1070 Assert.AreEqual (new Rectangle (211, 101, 95, 97), _labelF.Bounds, "A30");
\r
1072 p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;
\r
1073 Assert.AreEqual (new Rectangle (6, 3, 95, 95), _labelA.Bounds, "A31");
\r
1074 Assert.AreEqual (new Rectangle (110, 3, 95, 95), _labelB.Bounds, "A32");
\r
1075 Assert.AreEqual (new Rectangle (214, 3, 95, 95), _labelC.Bounds, "A33");
\r
1076 Assert.AreEqual (new Rectangle (6, 101, 95, 96), _labelD.Bounds, "A34");
\r
1077 Assert.AreEqual (new Rectangle (110, 101, 95, 96), _labelE.Bounds, "A35");
\r
1078 Assert.AreEqual (new Rectangle (214, 101, 95, 96), _labelF.Bounds, "A36");
\r
1080 p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetPartial;
\r
1081 Assert.AreEqual (new Rectangle (6, 3, 95, 95), _labelA.Bounds, "A37");
\r
1082 Assert.AreEqual (new Rectangle (110, 3, 95, 95), _labelB.Bounds, "A38");
\r
1083 Assert.AreEqual (new Rectangle (214, 3, 95, 95), _labelC.Bounds, "A39");
\r
1084 Assert.AreEqual (new Rectangle (6, 101, 95, 96), _labelD.Bounds, "A40");
\r
1085 Assert.AreEqual (new Rectangle (110, 101, 95, 96), _labelE.Bounds, "A41");
\r
1086 Assert.AreEqual (new Rectangle (214, 101, 95, 96), _labelF.Bounds, "A42");
\r
1092 public void Bug81936 ()
\r
1094 Form f = new Form ();
\r
1095 f.ShowInTaskbar = false;
\r
1097 TableLayoutPanel tableLayoutPanel1;
\r
1101 tableLayoutPanel1 = new TableLayoutPanel ();
\r
1102 button2 = new Label ();
\r
1103 button4 = new Label ();
\r
1104 button2.Text = "Test1";
\r
1105 button4.Text = "Test2";
\r
1106 button2.Anchor = AnchorStyles.Left;
\r
1107 button4.Anchor = AnchorStyles.Left;
\r
1108 button2.Height = 14;
\r
1109 button4.Height = 14;
\r
1110 tableLayoutPanel1.SuspendLayout ();
\r
1111 f.SuspendLayout ();
\r
1113 tableLayoutPanel1.ColumnCount = 1;
\r
1114 tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
\r
1115 tableLayoutPanel1.Controls.Add (button2, 0, 0);
\r
1116 tableLayoutPanel1.Controls.Add (button4, 0, 1);
\r
1117 tableLayoutPanel1.Location = new Point (0, 0);
\r
1118 tableLayoutPanel1.RowCount = 2;
\r
1119 tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Absolute, 28F));
\r
1120 tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Absolute, 28F));
\r
1121 tableLayoutPanel1.Size = new Size (292, 56);
\r
1123 f.ClientSize = new Size (292, 312);
\r
1124 f.Controls.Add (tableLayoutPanel1);
\r
1127 tableLayoutPanel1.ResumeLayout (false);
\r
1128 tableLayoutPanel1.PerformLayout ();
\r
1129 f.ResumeLayout (false);
\r
1130 f.PerformLayout ();
\r
1134 Assert.AreEqual (new Rectangle (3, 7, 100, 14), button2.Bounds, "A1");
\r
1135 Assert.AreEqual (new Rectangle (3, 35, 100, 14), button4.Bounds, "A2");
\r
1141 public void Bug82605 ()
\r
1143 Form f = new Form ();
\r
1144 f.ShowInTaskbar = false;
\r
1146 Label l = new Label ();
\r
1148 TableLayoutPanel table = new TableLayoutPanel ();
\r
1149 table.ColumnCount = 1;
\r
1150 table.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100F));
\r
1152 table.RowCount = 2;
\r
1153 table.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
\r
1154 table.RowStyles.Add (new RowStyle (SizeType.Absolute, 20F));
\r
1156 table.Controls.Add (l, 0, 1);
\r
1157 table.Location = new Point (0, 0);
\r
1158 table.Width = 250;
\r
1160 l.Anchor = AnchorStyles.Left | AnchorStyles.Right;
\r
1161 l.AutoSize = true;
\r
1162 l.Location = new Point (3, 352);
\r
1163 l.Size = new Size (578, 13);
\r
1164 l.Text = "label1";
\r
1165 l.TextAlign = ContentAlignment.MiddleCenter;
\r
1167 f.Controls.Add (table);
\r
1170 // Height is font dependent, but this bug is about the width anyways
\r
1171 Assert.AreEqual (244, l.Width, "A1");
\r
1174 [Test] // bug #82040
\r
1175 public void ShowNoChildren ()
\r
1177 Form form = new Form ();
\r
1178 form.ShowInTaskbar = false;
\r
1180 TableLayoutPanel tableLayoutPanel = new TableLayoutPanel ();
\r
1181 tableLayoutPanel.ColumnCount = 3;
\r
1182 tableLayoutPanel.Dock = DockStyle.Fill;
\r
1183 tableLayoutPanel.RowCount = 11;
\r
1184 form.Controls.Add (tableLayoutPanel);
\r
1191 [Test] // bug #82041
\r
1192 public void DontCallResumeLayout ()
\r
1194 Form form = new Form ();
\r
1195 form.ShowInTaskbar = false;
\r
1197 TableLayoutPanel tableLayoutPanel = new TableLayoutPanel ();
\r
1198 form.Controls.Add (tableLayoutPanel);
\r
1199 tableLayoutPanel.SuspendLayout ();
\r
1200 tableLayoutPanel.ColumnCount = 3;
\r
1201 tableLayoutPanel.Dock = DockStyle.Fill;
\r
1202 tableLayoutPanel.RowCount = 11;
\r
1203 tableLayoutPanel.Controls.Add (new Button ());
\r
1210 [Test] // bug #346246
\r
1211 public void AutoSizePanelVerical ()
\r
1213 Form f = new Form ();
\r
1214 f.ShowInTaskbar = false;
\r
1216 TableLayoutPanel tlp = new TableLayoutPanel ();
\r
1217 tlp.AutoSize = true;
\r
1218 tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
\r
1219 tlp.ColumnCount = 1;
\r
1220 tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100F));
\r
1221 tlp.Location = new Point (12, 12);
\r
1222 tlp.Name = "tableLayoutPanel1";
\r
1224 tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
\r
1225 tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
\r
1226 tlp.Size = new Size (139, 182);
\r
1229 f.Controls.Add (tlp);
\r
1231 Button b = new Button ();
\r
1232 b.Size = new Size (100, 100);
\r
1233 tlp.Controls.Add (b, 0, 0);
\r
1235 PictureBox p = new PictureBox ();
\r
1236 p.Size = new Size (100, 100);
\r
1237 tlp.Controls.Add (p,0,1);
\r
1241 Assert.AreEqual (new Rectangle (12, 12, 106, 212), tlp.Bounds, "A1");
\r
1242 Assert.AreEqual (new Rectangle (3, 3, 100, 100), b.Bounds, "A2");
\r
1243 Assert.AreEqual (new Rectangle (3, 109, 100, 100), p.Bounds, "A3");
\r
1248 Assert.AreEqual (new Rectangle (12, 12, 126, 252), tlp.Bounds, "B1");
\r
1249 Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "B2");
\r
1250 Assert.AreEqual (new Rectangle (3, 129, 100, 100), p.Bounds, "B3");
\r
1255 Assert.AreEqual (new Rectangle (12, 12, 126, 252), tlp.Bounds, "C1");
\r
1256 Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "C2");
\r
1257 Assert.AreEqual (new Rectangle (3, 129, 120, 120), p.Bounds, "C3");
\r
1262 [Test] // bug #346246
\r
1263 public void AutoSizePanelHorizontal ()
\r
1265 Form f = new Form ();
\r
1266 f.ShowInTaskbar = false;
\r
1268 TableLayoutPanel tlp = new TableLayoutPanel ();
\r
1269 tlp.AutoSize = true;
\r
1270 tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
\r
1271 tlp.ColumnCount = 2;
\r
1272 tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50F));
\r
1273 tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50F));
\r
1274 tlp.Location = new Point (12, 12);
\r
1275 tlp.Name = "tableLayoutPanel1";
\r
1277 tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
\r
1278 tlp.Size = new Size (139, 182);
\r
1281 f.Controls.Add (tlp);
\r
1283 Button b = new Button ();
\r
1284 b.Size = new Size (100, 100);
\r
1285 tlp.Controls.Add (b, 0, 0);
\r
1287 PictureBox p = new PictureBox ();
\r
1288 p.Size = new Size (100, 100);
\r
1289 tlp.Controls.Add (p, 1, 0);
\r
1293 Assert.AreEqual (new Rectangle (12, 12, 212, 106), tlp.Bounds, "A1");
\r
1294 Assert.AreEqual (new Rectangle (3, 3, 100, 100), b.Bounds, "A2");
\r
1295 Assert.AreEqual (new Rectangle (109, 3, 100, 100), p.Bounds, "A3");
\r
1300 Assert.AreEqual (new Rectangle (12, 12, 252, 126), tlp.Bounds, "B1");
\r
1301 Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "B2");
\r
1302 Assert.AreEqual (new Rectangle (129, 3, 100, 100), p.Bounds, "B3");
\r
1307 Assert.AreEqual (new Rectangle (12, 12, 252, 126), tlp.Bounds, "C1");
\r
1308 Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "C2");
\r
1309 Assert.AreEqual (new Rectangle (129, 3, 120, 120), p.Bounds, "C3");
\r
1315 public void Bug354676 ()
\r
1317 Form f = new Form ();
\r
1319 TableLayoutPanel tlp = new TableLayoutPanel ();
\r
1320 tlp.Dock = DockStyle.Fill;
\r
1321 tlp.Padding = new Padding (40);
\r
1323 tlp.ColumnCount = 1;
\r
1324 f.Controls.Add (tlp);
\r
1326 Button b1 = new Button ();
\r
1327 tlp.Controls.Add (b1);
\r
1329 Button b2 = new Button ();
\r
1330 tlp.Controls.Add (b2);
\r
1334 Assert.AreEqual (new Rectangle (43, 43, 75, 23), b1.Bounds, "A1");
\r
1335 Assert.AreEqual (new Rectangle (43, 72, 75, 23), b2.Bounds, "A2");
\r
1342 public void Bug355408 ()
\r
1344 Form f = new Form ();
\r
1345 f.ClientSize = new Size (300, 300);
\r
1347 TableLayoutPanel tlp = new TableLayoutPanel ();
\r
1348 tlp.Dock = DockStyle.Fill;
\r
1350 tlp.ColumnCount = 2;
\r
1351 f.Controls.Add (tlp);
\r
1353 Button b1 = new Button ();
\r
1354 tlp.Controls.Add (b1);
\r
1356 Button b2 = new Button ();
\r
1357 tlp.Controls.Add (b2);
\r
1359 Button b3 = new Button ();
\r
1360 b3.Dock = DockStyle.Fill;
\r
1362 tlp.SetColumnSpan (b3, 2);
\r
1363 tlp.Controls.Add (b3);
\r
1367 Assert.AreEqual (new Rectangle (3, 3, 75, 23), b1.Bounds, "A1");
\r
1368 Assert.AreEqual (new Rectangle (84, 3, 75, 23), b2.Bounds, "A2");
\r
1369 Assert.AreEqual (new Rectangle (3, 32, 294, 265), b3.Bounds, "A3");
\r
1376 public void Bug402651 ()
\r
1378 Form f = new Form ();
\r
1379 f.ClientSize = new Size (300, 300);
\r
1381 TableLayoutPanel tlp = new TableLayoutPanel ();
\r
1382 tlp.Dock = DockStyle.Fill;
\r
1384 tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
\r
1385 tlp.RowStyles.Add (new RowStyle (SizeType.AutoSize));
\r
1386 f.Controls.Add (tlp);
\r
1388 Button b1 = new Button ();
\r
1389 b1.Text = String.Empty;
\r
1390 b1.Dock = DockStyle.Fill;
\r
1391 tlp.Controls.Add (b1, 0, 0);
\r
1393 Button b2 = new Button ();
\r
1394 b2.Text = String.Empty;
\r
1395 b2.Size = new Size (100, 100);
\r
1396 b2.Anchor = AnchorStyles.None;
\r
1397 b2.Dock = DockStyle.None;
\r
1398 b2.Visible = false;
\r
1399 tlp.Controls.Add (b2, 0, 1);
\r
1403 b2.Visible = true;
\r
1404 Assert.AreEqual (new Size (100, 100), b2.Size, "A1");
\r
1406 b2.Visible = false;
\r
1407 b2.Anchor = AnchorStyles.Left;
\r
1408 b2.Visible = true;
\r
1409 Assert.AreEqual (new Size (100, 100), b2.Size, "A2");
\r
1415 public void Bug354672 ()
\r
1417 Form f = new Form ();
\r
1418 f.ClientSize = new Size (300, 300);
\r
1420 TableLayoutPanel tlp = new TableLayoutPanel ();
\r
1421 tlp.AutoSize = true;
\r
1422 tlp.ColumnCount = 2;
\r
1424 f.Controls.Add (tlp);
\r
1426 TextBox t1 = new TextBox ();
\r
1427 t1.Dock = DockStyle.Fill;
\r
1428 tlp.Controls.Add (t1);
\r
1430 TextBox t2 = new TextBox ();
\r
1431 t2.Dock = DockStyle.Fill;
\r
1432 tlp.Controls.Add (t2);
\r
1434 Assert.AreEqual (new Size (212, t1.Height + 6), tlp.PreferredSize, "A1");
\r
1440 public void Bug354672More ()
\r
1442 Form f = new Form ();
\r
1443 f.ClientSize = new Size (300, 300);
\r
1445 TableLayoutPanel tlp = new TableLayoutPanel ();
\r
1446 tlp.AutoSize = true;
\r
1447 tlp.ColumnCount = 2;
\r
1449 tlp.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
\r
1450 tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50f));
\r
1452 f.Controls.Add (tlp);
\r
1454 TextBox t1 = new TextBox ();
\r
1455 t1.Dock = DockStyle.Fill;
\r
1456 tlp.Controls.Add (t1);
\r
1458 TextBox t2 = new TextBox ();
\r
1459 t2.Dock = DockStyle.Fill;
\r
1460 tlp.Controls.Add (t2);
\r
1462 Assert.AreEqual (new Size (212, t1.Height + 6), tlp.PreferredSize, "A1");
\r
1468 public void Bug367249 ()
\r
1470 // Setting a colspan greater than the number of columns was
\r
1471 // causing an IOORE, this test just should not exception
\r
1472 TableLayoutPanel LayoutPanel = new TableLayoutPanel ();
\r
1473 LayoutPanel.ColumnCount = 1;
\r
1474 LayoutPanel.RowCount = 2;
\r
1476 Button OkButton = new Button ();
\r
1477 OkButton.Text = "OK";
\r
1478 LayoutPanel.Controls.Add (OkButton);
\r
1479 LayoutPanel.SetColumnSpan (OkButton, 3);
\r
1483 public void Bug396141 ()
\r
1485 // The issue is the user has set the RowCount to 0, but after
\r
1486 // we arrange the controls, we have 1 row. GetPreferredSize (for
\r
1487 // AutoSize) was using 0 instead of 1.
\r
1489 Form f = new Form ();
\r
1490 f.ClientSize = new Size (300, 300);
\r
1491 f.ShowInTaskbar = false;
\r
1493 TableLayoutPanel tlp = new TableLayoutPanel ();
\r
1494 tlp.AutoSize = true;
\r
1495 tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
\r
1496 tlp.ColumnCount = 2;
\r
1499 f.Controls.Add (tlp);
\r
1501 TextBox t1 = new TextBox ();
\r
1502 t1.Dock = DockStyle.Fill;
\r
1503 tlp.Controls.Add (t1);
\r
1505 TextBox t2 = new TextBox ();
\r
1506 t2.Dock = DockStyle.Fill;
\r
1507 tlp.Controls.Add (t2);
\r
1511 Assert.IsTrue (tlp.Height > 0, "Height must be > 0");
\r
1512 Assert.IsTrue (tlp.Width > 0, "Width must be > 0");
\r
1518 public void Bug396433 ()
\r
1520 // We were not taking the CellBorderStyle into account when calculating
\r
1521 // the preferred size.
\r
1522 Form f = new Form ();
\r
1523 f.ClientSize = new Size (300, 300);
\r
1524 f.ShowInTaskbar = false;
\r
1526 TableLayoutPanel tlp = new TableLayoutPanel ();
\r
1527 tlp.AutoSize = true;
\r
1528 tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
\r
1529 tlp.ColumnCount = 2;
\r
1532 f.Controls.Add (tlp);
\r
1534 Button t1 = new Button ();
\r
1535 tlp.Controls.Add (t1);
\r
1537 Button t2 = new Button ();
\r
1538 tlp.Controls.Add (t2);
\r
1542 Assert.AreEqual (new Size (162, 29), tlp.PreferredSize, "A1");
\r
1544 tlp.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
\r
1546 Assert.AreEqual (new Size (165, 31), tlp.PreferredSize, "A2");
\r
1552 public void IgnoreAutoSizeMode ()
\r
1554 // It would seem that AutoSizeMode for a TableLayoutPanel is always
\r
1555 // treated as GrowAndShrink
\r
1556 Form f = new Form ();
\r
1557 f.ClientSize = new Size (300, 300);
\r
1558 f.ShowInTaskbar = false;
\r
1560 TableLayoutPanel tlp = new TableLayoutPanel ();
\r
1561 tlp.AutoSize = true;
\r
1562 tlp.Dock = DockStyle.Top;
\r
1563 tlp.ColumnCount = 1;
\r
1566 f.Controls.Add (tlp);
\r
1568 Button t1 = new Button ();
\r
1569 tlp.Controls.Add (t1);
\r
1573 Assert.AreEqual (29, tlp.Height, "A1");
\r
1575 tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
\r
1577 Assert.AreEqual (29, tlp.Height, "A2");
\r
1583 public void TestTableLayoutStyleOwned ()
\r
1586 ColumnStyle style = new ColumnStyle ();
\r
1587 TableLayoutColumnStyleCollection coll = new TableLayoutPanel ().ColumnStyles;
\r
1589 TableLayoutColumnStyleCollection coll2 = new TableLayoutPanel ().ColumnStyles;
\r
1590 coll2.Add (style);
\r
1591 Assert.Fail ("#1");
\r
1592 } catch (ArgumentException ex) {
\r
1597 RowStyle style = new RowStyle ();
\r
1598 TableLayoutRowStyleCollection coll = new TableLayoutPanel ().RowStyles;
\r
1600 TableLayoutRowStyleCollection coll2 = new TableLayoutPanel ().RowStyles;
\r
1601 coll2.Add (style);
\r
1602 Assert.Fail ("#2");
\r
1603 } catch (ArgumentException ex) {
\r