Properly fill in the whole TableLayoutPanel with dummy controls
[mono.git] / mcs / class / Managed.Windows.Forms / Test / System.Windows.Forms / TableLayoutTest.cs
1 //\r
2 // TableLayoutTests.cs\r
3 //\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
11 // \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
14 // \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
22 //\r
23 // Copyright (c) 2006 Jonathan Pobst\r
24 //\r
25 // Authors:\r
26 //      Jonathan Pobst (monkey@jpobst.com)\r
27 //\r
28 \r
29 #if NET_2_0\r
30 using System;\r
31 using System.Drawing;\r
32 using System.Windows.Forms;\r
33 using NUnit.Framework;\r
34 \r
35 namespace MonoTests.System.Windows.Forms\r
36 {\r
37         [TestFixture]\r
38         public class TableLayoutTests : TestHelper\r
39         {\r
40                 [Test]\r
41                 public void TestConstruction ()\r
42                 {\r
43                         TableLayoutPanel p = new TableLayoutPanel ();\r
44 \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
55                 }\r
56 \r
57                 [Test]\r
58                 public void TestPropertySetters ()\r
59                 {\r
60                         TableLayoutPanel p = new TableLayoutPanel ();\r
61 \r
62                         p.BorderStyle = BorderStyle.Fixed3D;\r
63                         p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;\r
64                         p.ColumnCount = 1;\r
65                         p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;\r
66                         p.RowCount = 1;\r
67 \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
73                 }\r
74 \r
75                 [Test]\r
76                 public void TestExtenderMethods ()\r
77                 {\r
78                         TableLayoutPanel p = new TableLayoutPanel ();\r
79                         Control c = new Button ();\r
80 \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
86 \r
87                         p.SetCellPosition (c, new TableLayoutPanelCellPosition (1, 1));\r
88                         Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetCellPosition (c), "A6");\r
89 \r
90                         p.SetColumn (c, 2);\r
91                         Assert.AreEqual (2, p.GetColumn (c), "A7");\r
92                         p.SetRow (c, 2);\r
93                         Assert.AreEqual (2, p.GetRow (c), "A9");\r
94 \r
95                         p.SetColumnSpan (c, 2);\r
96                         Assert.AreEqual (2, p.GetColumnSpan (c), "A8");\r
97 \r
98 \r
99                         p.SetRowSpan (c, 2);\r
100                         Assert.AreEqual (2, p.GetRowSpan (c), "A10");\r
101 \r
102                         Assert.AreEqual (new TableLayoutPanelCellPosition (2, 2), p.GetCellPosition (c), "A11");\r
103 \r
104                         // ???????\r
105                         //Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetPositionFromControl (c), "A12");\r
106                         //Assert.AreEqual (c, p.GetControlFromPosition(0, 0), "A13");\r
107                 }\r
108 \r
109                 [Test]\r
110                 public void TestColumnStyles ()\r
111                 {\r
112                         TableLayoutPanel p = new TableLayoutPanel ();\r
113 \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
117 \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
125 \r
126                         p.ColumnStyles.Remove (p.ColumnStyles[0]);\r
127 \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
133                 }\r
134 \r
135                 [Test]\r
136                 public void TestRowStyles ()\r
137                 {\r
138                         TableLayoutPanel p = new TableLayoutPanel ();\r
139 \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
143 \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
151 \r
152                         p.RowStyles.Remove (p.RowStyles[0]);\r
153 \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
159                 }\r
160 \r
161                 [Test]\r
162                 public void TestColumnStyles3 ()\r
163                 {\r
164                         // Don't lose the 2nd style\r
165                         TableLayoutPanel p = new TableLayoutPanel ();\r
166 \r
167                         p.ColumnCount = 2;\r
168                         p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));\r
169                         p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));\r
170 \r
171                         p.ColumnCount = 1;\r
172 \r
173                         Assert.AreEqual (2, p.ColumnStyles.Count, "A1");\r
174                 }\r
175 \r
176                 [Test]\r
177                 public void TestColumnStyles2 ()\r
178                 {\r
179                         // Don't lose the 2nd style\r
180                         TableLayoutPanel p = new TableLayoutPanel ();\r
181 \r
182                         p.ColumnCount = 1;\r
183                         p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));\r
184 \r
185                         p.ColumnCount = 2;\r
186 \r
187                         Assert.AreEqual (1, p.ColumnStyles.Count, "A2");\r
188                 }\r
189 \r
190                 [Test]\r
191                 public void TestCellPositioning ()\r
192                 {\r
193                         // Standard Add\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
199 \r
200                         p.ColumnCount = 2;\r
201                         p.RowCount = 2;\r
202 \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
207 \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
212                 }\r
213 \r
214                 [Test]\r
215                 public void TestCellPositioning2 ()\r
216                 {\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
225 \r
226                         p.ColumnCount = 2;\r
227                         p.RowCount = 2;\r
228 \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
235 \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
242                 }\r
243 \r
244                 [Test]\r
245                 public void TestCellPositioning3 ()\r
246                 {\r
247                         // Growstyle = Add Columns\r
248                         TableLayoutPanel p = new TableLayoutPanel ();\r
249                         p.GrowStyle = TableLayoutPanelGrowStyle.AddColumns;\r
250 \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
257 \r
258                         p.ColumnCount = 2;\r
259                         p.RowCount = 2;\r
260 \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
267 \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
274                 }\r
275 \r
276                 [Test]\r
277                 [ExpectedException (typeof (ArgumentException))]\r
278                 public void TestCellPositioning4 ()\r
279                 {\r
280                         // Growstyle = Fixed Size\r
281                         TableLayoutPanel p = new TableLayoutPanel ();\r
282                         p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;\r
283 \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
289 \r
290                         p.ColumnCount = 2;\r
291                         p.RowCount = 2;\r
292 \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
298                 }\r
299 \r
300                 [Test]\r
301                 public void TestCellPositioning5 ()\r
302                 {\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
309 \r
310                         p.ColumnCount = 2;\r
311                         p.RowCount = 2;\r
312 \r
313                         p.SetCellPosition (c4, new TableLayoutPanelCellPosition (0, 0));\r
314 \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
319 \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
324                 }\r
325 \r
326                 [Test]\r
327                 public void TestCellPositioning6 ()\r
328                 {\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
335 \r
336                         p.ColumnCount = 2;\r
337                         p.RowCount = 2;\r
338 \r
339                         p.SetColumn (c3, 1);\r
340 \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
345 \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
350                 }\r
351 \r
352                 [Test]\r
353                 public void TestCellPositioning7 ()\r
354                 {\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
361 \r
362                         p.ColumnCount = 2;\r
363                         p.RowCount = 2;\r
364 \r
365                         p.SetColumn (c3, 1);\r
366                         p.SetRow (c3, 1);\r
367 \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
372 \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
377                 }\r
378 \r
379                 [Test]\r
380                 public void TestCellPositioning8 ()\r
381                 {\r
382                         // Column span\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
387 \r
388                         p.ColumnCount = 2;\r
389                         p.RowCount = 2;\r
390 \r
391                         p.SetColumnSpan (c1, 2);\r
392 \r
393                         p.Controls.Add (c1);\r
394                         p.Controls.Add (c2);\r
395                         p.Controls.Add (c3);\r
396 \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
400                 }\r
401 \r
402                 [Test]\r
403                 public void TestCellPositioning9 ()\r
404                 {\r
405                         // Row span\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
410 \r
411                         p.ColumnCount = 2;\r
412                         p.RowCount = 2;\r
413 \r
414                         p.SetRowSpan (c1, 2);\r
415 \r
416                         p.Controls.Add (c1);\r
417                         p.Controls.Add (c2);\r
418                         p.Controls.Add (c3);\r
419 \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
423                 }\r
424 \r
425                 [Test]\r
426                 public void TestCellPositioning10 ()\r
427                 {\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
434 \r
435                         p.ColumnCount = 2;\r
436                         p.RowCount = 2;\r
437 \r
438                         p.SetColumnSpan (c2, 2);\r
439 \r
440                         p.Controls.Add (c1);\r
441                         p.Controls.Add (c2);\r
442                         p.Controls.Add (c3);\r
443 \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
447                 }\r
448 \r
449                 [Test]\r
450                 public void TestCellPositioning11 ()\r
451                 {\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
457 \r
458                         p.ColumnCount = 2;\r
459                         p.RowCount = 2;\r
460 \r
461                         p.SetRowSpan (c3, 2);\r
462 \r
463                         p.Controls.Add (c1);\r
464                         p.Controls.Add (c2);\r
465                         p.Controls.Add (c3);\r
466 \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
470                 }\r
471 \r
472                 [Test]\r
473                 public void TestCellPositioning12 ()\r
474                 {\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
480 \r
481                         p.ColumnCount = 2;\r
482                         p.RowCount = 2;\r
483 \r
484                         p.SetColumn (c1, 4);\r
485 \r
486                         p.Controls.Add (c1);\r
487                         p.Controls.Add (c2);\r
488                         p.Controls.Add (c3);\r
489 \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
493                 }\r
494 \r
495                 [Test]\r
496                 public void TestCellPositioning13 ()\r
497                 {\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
503 \r
504                         p.ColumnCount = 3;\r
505                         p.RowCount = 2;\r
506 \r
507                         p.SetRowSpan (c3, 2);\r
508 \r
509                         p.Controls.Add (c1);\r
510                         p.Controls.Add (c2);\r
511                         p.Controls.Add (c3);\r
512 \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
516                 }\r
517 \r
518                 [Test]\r
519                 [Category ("NotWorking")]\r
520                 public void TestCellPositioning14 ()\r
521                 {\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
526 \r
527                         p.ColumnCount = 2;\r
528                         p.RowCount = 2;\r
529 \r
530                         p.SetColumnSpan (c1, 3);\r
531 \r
532                         p.Controls.Add (c1);\r
533 \r
534                         Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");\r
535                 }\r
536 \r
537                 [Test]\r
538                 public void TestCellPositioning15 ()\r
539                 {\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
546 \r
547                         p.ColumnCount = 2;\r
548                         p.RowCount = 2;\r
549 \r
550                         p.SetColumnSpan (c2, 2);\r
551                         p.SetCellPosition (c2, new TableLayoutPanelCellPosition (1, 0));\r
552 \r
553                         p.Controls.Add (c1);\r
554                         p.Controls.Add (c2);\r
555                         p.Controls.Add (c3);\r
556 \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
560                 }\r
561 \r
562                 [Test]\r
563                 public void TestCellPositioning16 ()\r
564                 {\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
570 \r
571                         p.ColumnCount = 2;\r
572                         p.RowCount = 2;\r
573 \r
574                         p.SetRowSpan (c3, 2);\r
575                         p.SetCellPosition (c3, new TableLayoutPanelCellPosition (0, 1));\r
576 \r
577                         p.Controls.Add (c1);\r
578                         p.Controls.Add (c2);\r
579                         p.Controls.Add (c3);\r
580 \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
584                 }\r
585 \r
586                 [Test]\r
587                 public void TestCellPositioning17 ()\r
588                 {\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
591                         //\r
592                         TableLayoutPanel p = new TableLayoutPanel ();\r
593                         p.ColumnCount = 0;\r
594                         p.RowCount = 0;\r
595                         Control c1 = new Button ();\r
596 \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
601                 }\r
602 \r
603                 [Test]\r
604                 public void TestCellPositioning18 ()\r
605                 {\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
614 \r
615                         p.ColumnCount = 3;\r
616                         p.RowCount = 4;\r
617 \r
618                         p.SetRowSpan (c1, 2);\r
619                         p.SetColumnSpan (c1, 2);\r
620                         p.SetCellPosition (c1, new TableLayoutPanelCellPosition (0, 0));\r
621 \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
626 \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
631                 }\r
632 \r
633                 [Test]\r
634                 public void TestRowColumnSizes1 ()\r
635                 {\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
641 \r
642                         p.ColumnCount = 2;\r
643                         p.RowCount = 1;\r
644 \r
645                         p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));\r
646 \r
647                         p.Controls.Add (c1);\r
648                         p.Controls.Add (c2);\r
649                         p.Controls.Add (c3);\r
650 \r
651                         Assert.AreEqual (71, p.GetRowHeights ()[0], "D1");\r
652                         Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");\r
653                 }\r
654 \r
655                 [Test]\r
656                 public void TestRowColumnSizes2 ()\r
657                 {\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
663 \r
664                         p.ColumnCount = 2;\r
665                         p.RowCount = 1;\r
666 \r
667                         p.RowStyles.Add (new RowStyle (SizeType.Absolute, 100F));\r
668 \r
669                         p.Controls.Add (c1);\r
670                         p.Controls.Add (c2);\r
671                         p.Controls.Add (c3);\r
672 \r
673                         Assert.AreEqual (100, p.GetRowHeights ()[0], "D1");\r
674                         Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");\r
675                 }\r
676 \r
677                 [Test]\r
678                 public void TestRowColumnSizes3 ()\r
679                 {\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
687 \r
688                         p.ColumnCount = 2;\r
689                         p.RowCount = 1;\r
690 \r
691                         p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));\r
692 \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
698 \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
702                 }\r
703 \r
704                 [Test]\r
705                 public void TestRowColumnSizes4 ()\r
706                 {\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
716 \r
717                         p.ColumnCount = 2;\r
718                         p.RowCount = 1;\r
719 \r
720                         p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));\r
721 \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
729 \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
734                 }\r
735 \r
736                 [Test]\r
737                 public void TestRowColumnSizes5 ()\r
738                 {\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
744 \r
745                         p.ColumnCount = 2;\r
746                         p.RowCount = 2;\r
747 \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
752 \r
753                         p.Controls.Add (c1);\r
754                         p.Controls.Add (c2);\r
755                         p.Controls.Add (c3);\r
756 \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
761                 }\r
762 \r
763                 [Test]\r
764                 public void TestRowColumnSizes6 ()\r
765                 {\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
771 \r
772                         p.ColumnCount = 2;\r
773                         p.RowCount = 2;\r
774 \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
779 \r
780                         p.Controls.Add (c1);\r
781                         p.Controls.Add (c2);\r
782                         p.Controls.Add (c3);\r
783 \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
788                 }\r
789 \r
790                 [Test]\r
791                 public void TestRowColumnSizes7 ()\r
792                 {\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
798 \r
799                         p.ColumnCount = 3;\r
800                         p.RowCount = 3;\r
801 \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
808 \r
809                         p.Controls.Add (c1);\r
810                         p.Controls.Add (c2);\r
811                         p.Controls.Add (c3);\r
812 \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
819                 }\r
820 \r
821                 [Test]\r
822                 public void TestRowColumnSizes8 ()\r
823                 {\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
829 \r
830                         p.ColumnCount = 3;\r
831                         p.RowCount = 3;\r
832 \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
839 \r
840                         p.Controls.Add (c1);\r
841                         p.Controls.Add (c2);\r
842                         p.Controls.Add (c3);\r
843 \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
850                 }\r
851 \r
852                 [Test]\r
853                 public void TestRowColumnSizes9 ()\r
854                 {\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
860 \r
861                         p.ColumnCount = 3;\r
862                         p.RowCount = 3;\r
863 \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
870 \r
871                         p.Controls.Add (c1);\r
872                         p.Controls.Add (c2);\r
873                         p.Controls.Add (c3);\r
874 \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
881                 }\r
882 \r
883                 [Test]\r
884                 public void TestRowColumnSizes10 ()\r
885                 {\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
891 \r
892                         p.ColumnCount = 2;\r
893                         p.RowCount = 2;\r
894 \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
899 \r
900                         p.Controls.Add (c1);\r
901                         p.Controls.Add (c2);\r
902                         p.Controls.Add (c3);\r
903 \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
908                 }\r
909                 \r
910                 [Test]\r
911                 public void Bug81843 ()\r
912                 {\r
913                         Form f = new Form ();\r
914                         f.ShowInTaskbar = false;\r
915                         \r
916                         TableLayoutPanel tableLayoutPanel1;\r
917                         Button button2;\r
918                         TextBox textBox1;\r
919                         Button button4;\r
920 \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
927 \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
941 \r
942                         button2.Size = new Size (75, 23);\r
943                         \r
944                         button4.Size = new Size (75, 23);\r
945 \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
950 \r
951                         f.ClientSize = new Size (292, 312);\r
952                         f.Controls.Add (tableLayoutPanel1);\r
953                         f.Name = "Form1";\r
954                         f.Text = "Form1";\r
955                         tableLayoutPanel1.ResumeLayout (false);\r
956                         tableLayoutPanel1.PerformLayout ();\r
957                         f.ResumeLayout (false);\r
958                         f.PerformLayout ();\r
959 \r
960                         f.Show ();\r
961 \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
965                         \r
966                         f.Dispose ();\r
967                 }\r
968                 \r
969                 [Test]  // From bug #81884\r
970                 public void CellBorderStyle ()\r
971                 {\r
972                         Form f = new Form ();\r
973                         f.ShowInTaskbar = false;\r
974 \r
975                         TableLayoutPanel p = new TableLayoutPanel ();\r
976                         p = new TableLayoutPanel ();\r
977                         p.ColumnCount = 3;\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
982                         p.Height = 200;\r
983                         p.RowCount = 2;\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
987 \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
993 \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
999 \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
1005 \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
1011 \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
1017 \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
1023 \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
1030 \r
1031                         f.Show ();\r
1032                         // None\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
1039                         \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
1047 \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
1055 \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
1063 \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
1071 \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
1079 \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
1087                         \r
1088                         f.Close ();\r
1089                 }\r
1090 \r
1091                 [Test]\r
1092                 public void Bug81936 ()\r
1093                 {\r
1094                         Form f = new Form ();\r
1095                         f.ShowInTaskbar = false;\r
1096 \r
1097                         TableLayoutPanel tableLayoutPanel1;\r
1098                         Label button2;\r
1099                         Label button4;\r
1100 \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
1112 \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
1122 \r
1123                         f.ClientSize = new Size (292, 312);\r
1124                         f.Controls.Add (tableLayoutPanel1);\r
1125                         f.Name = "Form1";\r
1126                         f.Text = "Form1";\r
1127                         tableLayoutPanel1.ResumeLayout (false);\r
1128                         tableLayoutPanel1.PerformLayout ();\r
1129                         f.ResumeLayout (false);\r
1130                         f.PerformLayout ();\r
1131 \r
1132                         f.Show ();\r
1133 \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
1136 \r
1137                         f.Dispose ();\r
1138                 }\r
1139 \r
1140                 [Test]\r
1141                 public void Bug82605 ()\r
1142                 {\r
1143                         Form f = new Form ();\r
1144                         f.ShowInTaskbar = false;\r
1145                         \r
1146                         Label l = new Label ();\r
1147 \r
1148                         TableLayoutPanel table = new TableLayoutPanel ();\r
1149                         table.ColumnCount = 1;\r
1150                         table.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100F));\r
1151 \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
1155 \r
1156                         table.Controls.Add (l, 0, 1);\r
1157                         table.Location = new Point (0, 0);\r
1158                         table.Width = 250;\r
1159 \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
1166 \r
1167                         f.Controls.Add (table);\r
1168                         f.Show ();\r
1169                         \r
1170                         // Height is font dependent, but this bug is about the width anyways\r
1171                         Assert.AreEqual (244, l.Width, "A1");\r
1172                 }\r
1173                 \r
1174                 [Test] // bug #82040\r
1175                 public void ShowNoChildren ()\r
1176                 {\r
1177                         Form form = new Form ();\r
1178                         form.ShowInTaskbar = false;\r
1179 \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
1185 \r
1186                         form.Show ();\r
1187                         form.Refresh ();\r
1188                         form.Dispose ();\r
1189                 }\r
1190 \r
1191                 [Test] // bug #82041\r
1192                 public void DontCallResumeLayout ()\r
1193                 {\r
1194                         Form form = new Form ();\r
1195                         form.ShowInTaskbar = false;\r
1196 \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
1204 \r
1205                         form.Show ();\r
1206                         form.Refresh ();\r
1207                         form.Dispose ();\r
1208                 }\r
1209                 \r
1210                 [Test] // bug #346246\r
1211                 public void AutoSizePanelVerical ()\r
1212                 {\r
1213                         Form f = new Form ();\r
1214                         f.ShowInTaskbar = false;\r
1215                         \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
1223                         tlp.RowCount = 2;\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
1227                         tlp.TabIndex = 0;\r
1228 \r
1229                         f.Controls.Add (tlp);\r
1230 \r
1231                         Button b = new Button ();\r
1232                         b.Size = new Size (100, 100);\r
1233                         tlp.Controls.Add (b, 0, 0);\r
1234 \r
1235                         PictureBox p = new PictureBox ();\r
1236                         p.Size = new Size (100, 100);\r
1237                         tlp.Controls.Add (p,0,1);\r
1238                         \r
1239                         f.Show ();\r
1240 \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
1244                         \r
1245                         b.Width += 20;\r
1246                         b.Height += 20;\r
1247 \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
1251 \r
1252                         p.Width += 20;\r
1253                         p.Height += 20;\r
1254 \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
1258                         \r
1259                         f.Dispose ();\r
1260                 }\r
1261 \r
1262                 [Test] // bug #346246\r
1263                 public void AutoSizePanelHorizontal ()\r
1264                 {\r
1265                         Form f = new Form ();\r
1266                         f.ShowInTaskbar = false;\r
1267 \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
1276                         tlp.RowCount = 1;\r
1277                         tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));\r
1278                         tlp.Size = new Size (139, 182);\r
1279                         tlp.TabIndex = 0;\r
1280 \r
1281                         f.Controls.Add (tlp);\r
1282 \r
1283                         Button b = new Button ();\r
1284                         b.Size = new Size (100, 100);\r
1285                         tlp.Controls.Add (b, 0, 0);\r
1286 \r
1287                         PictureBox p = new PictureBox ();\r
1288                         p.Size = new Size (100, 100);\r
1289                         tlp.Controls.Add (p, 1, 0);\r
1290 \r
1291                         f.Show ();\r
1292 \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
1296 \r
1297                         b.Width += 20;\r
1298                         b.Height += 20;\r
1299 \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
1303 \r
1304                         p.Width += 20;\r
1305                         p.Height += 20;\r
1306 \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
1310 \r
1311                         f.Dispose ();\r
1312                 }\r
1313                 \r
1314                 [Test]\r
1315                 public void Bug354676 ()\r
1316                 {\r
1317                         Form f = new Form ();\r
1318 \r
1319                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1320                         tlp.Dock = DockStyle.Fill;\r
1321                         tlp.Padding = new Padding (40);\r
1322                         tlp.RowCount = 2;\r
1323                         tlp.ColumnCount = 1;\r
1324                         f.Controls.Add (tlp);\r
1325 \r
1326                         Button b1 = new Button ();\r
1327                         tlp.Controls.Add (b1);\r
1328 \r
1329                         Button b2 = new Button ();\r
1330                         tlp.Controls.Add (b2);\r
1331 \r
1332                         f.Show ();\r
1333 \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
1336                         \r
1337                         f.Close ();\r
1338                         f.Dispose ();\r
1339                 }\r
1340                 \r
1341                 [Test]\r
1342                 public void Bug355408 ()\r
1343                 {\r
1344                         Form f = new Form ();\r
1345                         f.ClientSize = new Size (300, 300);\r
1346                         \r
1347                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1348                         tlp.Dock = DockStyle.Fill;\r
1349                         tlp.RowCount = 2;\r
1350                         tlp.ColumnCount = 2;\r
1351                         f.Controls.Add (tlp);\r
1352 \r
1353                         Button b1 = new Button ();\r
1354                         tlp.Controls.Add (b1);\r
1355 \r
1356                         Button b2 = new Button ();\r
1357                         tlp.Controls.Add (b2);\r
1358                         \r
1359                         Button b3 = new Button ();\r
1360                         b3.Dock = DockStyle.Fill;\r
1361                         b3.Width = 250;\r
1362                         tlp.SetColumnSpan (b3, 2);\r
1363                         tlp.Controls.Add (b3);\r
1364 \r
1365                         f.Show ();\r
1366 \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
1370 \r
1371                         f.Close ();\r
1372                         f.Dispose ();\r
1373                 }\r
1374                 \r
1375                 [Test]\r
1376                 public void Bug402651 ()\r
1377                 {\r
1378                         Form f = new Form ();\r
1379                         f.ClientSize = new Size (300, 300);\r
1380 \r
1381                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1382                         tlp.Dock = DockStyle.Fill;\r
1383                         tlp.RowCount = 2;\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
1387 \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
1392 \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
1400 \r
1401                         f.Show ();\r
1402 \r
1403                         b2.Visible = true;\r
1404                         Assert.AreEqual (new Size (100, 100), b2.Size, "A1");\r
1405 \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
1410 \r
1411                         f.Dispose ();\r
1412                 }\r
1413 \r
1414                 [Test]\r
1415                 public void Bug354672 ()\r
1416                 {\r
1417                         Form f = new Form ();\r
1418                         f.ClientSize = new Size (300, 300);\r
1419 \r
1420                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1421                         tlp.AutoSize = true;\r
1422                         tlp.ColumnCount = 2;\r
1423                         tlp.RowCount = 1;\r
1424                         f.Controls.Add (tlp);\r
1425 \r
1426                         TextBox t1 = new TextBox ();\r
1427                         t1.Dock = DockStyle.Fill;\r
1428                         tlp.Controls.Add (t1);\r
1429 \r
1430                         TextBox t2 = new TextBox ();\r
1431                         t2.Dock = DockStyle.Fill;\r
1432                         tlp.Controls.Add (t2);\r
1433 \r
1434                         Assert.AreEqual (new Size (212, t1.Height + 6), tlp.PreferredSize, "A1");\r
1435 \r
1436                         f.Dispose ();\r
1437                 }\r
1438 \r
1439                 [Test]\r
1440                 public void Bug354672More ()\r
1441                 {\r
1442                         Form f = new Form ();\r
1443                         f.ClientSize = new Size (300, 300);\r
1444 \r
1445                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1446                         tlp.AutoSize = true;\r
1447                         tlp.ColumnCount = 2;\r
1448                         tlp.RowCount = 1;\r
1449                         tlp.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));\r
1450                         tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50f));\r
1451                         \r
1452                         f.Controls.Add (tlp);\r
1453 \r
1454                         TextBox t1 = new TextBox ();\r
1455                         t1.Dock = DockStyle.Fill;\r
1456                         tlp.Controls.Add (t1);\r
1457 \r
1458                         TextBox t2 = new TextBox ();\r
1459                         t2.Dock = DockStyle.Fill;\r
1460                         tlp.Controls.Add (t2);\r
1461 \r
1462                         Assert.AreEqual (new Size (212, t1.Height + 6), tlp.PreferredSize, "A1");\r
1463 \r
1464                         f.Dispose ();\r
1465                 }\r
1466                 \r
1467                 [Test]\r
1468                 public void Bug367249 ()\r
1469                 {\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
1475 \r
1476                         Button OkButton = new Button ();\r
1477                         OkButton.Text = "OK";\r
1478                         LayoutPanel.Controls.Add (OkButton);\r
1479                         LayoutPanel.SetColumnSpan (OkButton, 3);\r
1480                 }\r
1481                 \r
1482                 [Test]\r
1483                 public void Bug396141 ()\r
1484                 {\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
1488 \r
1489                         Form f = new Form ();\r
1490                         f.ClientSize = new Size (300, 300);\r
1491                         f.ShowInTaskbar = false;\r
1492 \r
1493                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1494                         tlp.AutoSize = true;\r
1495                         tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;\r
1496                         tlp.ColumnCount = 2;\r
1497                         tlp.RowCount = 0;\r
1498 \r
1499                         f.Controls.Add (tlp);\r
1500 \r
1501                         TextBox t1 = new TextBox ();\r
1502                         t1.Dock = DockStyle.Fill;\r
1503                         tlp.Controls.Add (t1);\r
1504 \r
1505                         TextBox t2 = new TextBox ();\r
1506                         t2.Dock = DockStyle.Fill;\r
1507                         tlp.Controls.Add (t2);\r
1508 \r
1509                         f.Show ();\r
1510                         \r
1511                         Assert.IsTrue (tlp.Height > 0, "Height must be > 0");\r
1512                         Assert.IsTrue (tlp.Width > 0, "Width must be > 0");\r
1513 \r
1514                         f.Dispose ();\r
1515                 }\r
1516                 \r
1517                 [Test]\r
1518                 public void Bug396433 ()\r
1519                 {\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
1525 \r
1526                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1527                         tlp.AutoSize = true;\r
1528                         tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;\r
1529                         tlp.ColumnCount = 2;\r
1530                         tlp.RowCount = 1;\r
1531 \r
1532                         f.Controls.Add (tlp);\r
1533 \r
1534                         Button t1 = new Button ();\r
1535                         tlp.Controls.Add (t1);\r
1536 \r
1537                         Button t2 = new Button ();\r
1538                         tlp.Controls.Add (t2);\r
1539 \r
1540                         f.Show ();\r
1541 \r
1542                         Assert.AreEqual (new Size (162, 29), tlp.PreferredSize, "A1");\r
1543                         \r
1544                         tlp.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;\r
1545 \r
1546                         Assert.AreEqual (new Size (165, 31), tlp.PreferredSize, "A2");\r
1547 \r
1548                         f.Dispose ();\r
1549                 }\r
1550                 \r
1551                 [Test]\r
1552                 public void IgnoreAutoSizeMode ()\r
1553                 {\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
1559 \r
1560                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1561                         tlp.AutoSize = true;\r
1562                         tlp.Dock = DockStyle.Top;\r
1563                         tlp.ColumnCount = 1;\r
1564                         tlp.RowCount = 1;\r
1565 \r
1566                         f.Controls.Add (tlp);\r
1567 \r
1568                         Button t1 = new Button ();\r
1569                         tlp.Controls.Add (t1);\r
1570 \r
1571                         f.Show ();\r
1572 \r
1573                         Assert.AreEqual (29, tlp.Height, "A1");\r
1574 \r
1575                         tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;\r
1576 \r
1577                         Assert.AreEqual (29, tlp.Height, "A2");\r
1578 \r
1579                         f.Dispose ();\r
1580                 }\r
1581 \r
1582                 [Test]\r
1583                 public void TestTableLayoutStyleOwned ()\r
1584                 {\r
1585                         try {\r
1586                                 ColumnStyle style = new ColumnStyle ();\r
1587                                 TableLayoutColumnStyleCollection coll = new TableLayoutPanel ().ColumnStyles;\r
1588                                 coll.Add (style);\r
1589                                 TableLayoutColumnStyleCollection coll2 = new TableLayoutPanel ().ColumnStyles;\r
1590                                 coll2.Add (style);\r
1591                                 Assert.Fail ("#1");\r
1592                         } catch (ArgumentException ex) {\r
1593                                 // PASS\r
1594                         }\r
1595 \r
1596                         try {\r
1597                                 RowStyle style = new RowStyle ();\r
1598                                 TableLayoutRowStyleCollection coll = new TableLayoutPanel ().RowStyles;\r
1599                                 coll.Add (style);\r
1600                                 TableLayoutRowStyleCollection coll2 = new TableLayoutPanel ().RowStyles;\r
1601                                 coll2.Add (style);\r
1602                                 Assert.Fail ("#2");\r
1603                         } catch (ArgumentException ex) {\r
1604                                 // PASS\r
1605                         }\r
1606                 }\r
1607         }\r
1608 }\r
1609 #endif\r