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