feb073922441ea307c0c971b81baeae7fb95cfb6
[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.IO;\r
33 using System.Runtime.Serialization.Formatters.Binary;\r
34 using System.Windows.Forms;\r
35 using NUnit.Framework;\r
36 \r
37 namespace MonoTests.System.Windows.Forms\r
38 {\r
39         [TestFixture]\r
40         public class TableLayoutTests : TestHelper\r
41         {\r
42                 [Test]\r
43                 public void TestConstruction ()\r
44                 {\r
45                         TableLayoutPanel p = new TableLayoutPanel ();\r
46 \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
57                 }\r
58 \r
59                 [Test]\r
60                 public void TestPropertySetters ()\r
61                 {\r
62                         TableLayoutPanel p = new TableLayoutPanel ();\r
63 \r
64                         p.BorderStyle = BorderStyle.Fixed3D;\r
65                         p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;\r
66                         p.ColumnCount = 1;\r
67                         p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;\r
68                         p.RowCount = 1;\r
69 \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
75                 }\r
76 \r
77                 [Test]\r
78                 public void TestExtenderMethods ()\r
79                 {\r
80                         TableLayoutPanel p = new TableLayoutPanel ();\r
81                         Control c = new Button ();\r
82 \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
88 \r
89                         p.SetCellPosition (c, new TableLayoutPanelCellPosition (1, 1));\r
90                         Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetCellPosition (c), "A6");\r
91 \r
92                         p.SetColumn (c, 2);\r
93                         Assert.AreEqual (2, p.GetColumn (c), "A7");\r
94                         p.SetRow (c, 2);\r
95                         Assert.AreEqual (2, p.GetRow (c), "A9");\r
96 \r
97                         p.SetColumnSpan (c, 2);\r
98                         Assert.AreEqual (2, p.GetColumnSpan (c), "A8");\r
99 \r
100 \r
101                         p.SetRowSpan (c, 2);\r
102                         Assert.AreEqual (2, p.GetRowSpan (c), "A10");\r
103 \r
104                         Assert.AreEqual (new TableLayoutPanelCellPosition (2, 2), p.GetCellPosition (c), "A11");\r
105 \r
106                         // ???????\r
107                         //Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetPositionFromControl (c), "A12");\r
108                         //Assert.AreEqual (c, p.GetControlFromPosition(0, 0), "A13");\r
109                 }\r
110 \r
111                 [Test]\r
112                 public void TestColumnStyles ()\r
113                 {\r
114                         TableLayoutPanel p = new TableLayoutPanel ();\r
115 \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
119 \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
127 \r
128                         p.ColumnStyles.Remove (p.ColumnStyles[0]);\r
129 \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
135                 }\r
136 \r
137                 [Test]\r
138                 public void TestRowStyles ()\r
139                 {\r
140                         TableLayoutPanel p = new TableLayoutPanel ();\r
141 \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
145 \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
153 \r
154                         p.RowStyles.Remove (p.RowStyles[0]);\r
155 \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
161                 }\r
162 \r
163                 [Test]\r
164                 public void TestColumnStyles3 ()\r
165                 {\r
166                         // Don't lose the 2nd style\r
167                         TableLayoutPanel p = new TableLayoutPanel ();\r
168 \r
169                         p.ColumnCount = 2;\r
170                         p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));\r
171                         p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));\r
172 \r
173                         p.ColumnCount = 1;\r
174 \r
175                         Assert.AreEqual (2, p.ColumnStyles.Count, "A1");\r
176                 }\r
177 \r
178                 [Test]\r
179                 public void TestColumnStyles2 ()\r
180                 {\r
181                         // Don't lose the 2nd style\r
182                         TableLayoutPanel p = new TableLayoutPanel ();\r
183 \r
184                         p.ColumnCount = 1;\r
185                         p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));\r
186 \r
187                         p.ColumnCount = 2;\r
188 \r
189                         Assert.AreEqual (1, p.ColumnStyles.Count, "A2");\r
190                 }\r
191 \r
192                 [Test]\r
193                 public void TestCellPositioning ()\r
194                 {\r
195                         // Standard Add\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
201 \r
202                         p.ColumnCount = 2;\r
203                         p.RowCount = 2;\r
204 \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
209 \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
214                 }\r
215 \r
216                 [Test]\r
217                 public void TestCellPositioning2 ()\r
218                 {\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
227 \r
228                         p.ColumnCount = 2;\r
229                         p.RowCount = 2;\r
230 \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
237 \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
244                 }\r
245 \r
246                 [Test]\r
247                 public void TestCellPositioning3 ()\r
248                 {\r
249                         // Growstyle = Add Columns\r
250                         TableLayoutPanel p = new TableLayoutPanel ();\r
251                         p.GrowStyle = TableLayoutPanelGrowStyle.AddColumns;\r
252 \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
259 \r
260                         p.ColumnCount = 2;\r
261                         p.RowCount = 2;\r
262 \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
269 \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
276                 }\r
277 \r
278                 [Test]\r
279                 [ExpectedException (typeof (ArgumentException))]\r
280                 public void TestCellPositioning4 ()\r
281                 {\r
282                         // Growstyle = Fixed Size\r
283                         TableLayoutPanel p = new TableLayoutPanel ();\r
284                         p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;\r
285 \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
291 \r
292                         p.ColumnCount = 2;\r
293                         p.RowCount = 2;\r
294 \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
300                 }\r
301 \r
302                 [Test]\r
303                 public void TestCellPositioning5 ()\r
304                 {\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
311 \r
312                         p.ColumnCount = 2;\r
313                         p.RowCount = 2;\r
314 \r
315                         p.SetCellPosition (c4, new TableLayoutPanelCellPosition (0, 0));\r
316 \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
321 \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
326                 }\r
327 \r
328                 [Test]\r
329                 public void TestCellPositioning6 ()\r
330                 {\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
337 \r
338                         p.ColumnCount = 2;\r
339                         p.RowCount = 2;\r
340 \r
341                         p.SetColumn (c3, 1);\r
342 \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
347 \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
352                 }\r
353 \r
354                 [Test]\r
355                 public void TestCellPositioning7 ()\r
356                 {\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
363 \r
364                         p.ColumnCount = 2;\r
365                         p.RowCount = 2;\r
366 \r
367                         p.SetColumn (c3, 1);\r
368                         p.SetRow (c3, 1);\r
369 \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
374 \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
379                 }\r
380 \r
381                 [Test]\r
382                 public void TestCellPositioning8 ()\r
383                 {\r
384                         // Column span\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
389 \r
390                         p.ColumnCount = 2;\r
391                         p.RowCount = 2;\r
392 \r
393                         p.SetColumnSpan (c1, 2);\r
394 \r
395                         p.Controls.Add (c1);\r
396                         p.Controls.Add (c2);\r
397                         p.Controls.Add (c3);\r
398 \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
402                 }\r
403 \r
404                 [Test]\r
405                 public void TestCellPositioning9 ()\r
406                 {\r
407                         // Row span\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
412 \r
413                         p.ColumnCount = 2;\r
414                         p.RowCount = 2;\r
415 \r
416                         p.SetRowSpan (c1, 2);\r
417 \r
418                         p.Controls.Add (c1);\r
419                         p.Controls.Add (c2);\r
420                         p.Controls.Add (c3);\r
421 \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
425                 }\r
426 \r
427                 [Test]\r
428                 public void TestCellPositioning10 ()\r
429                 {\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
436 \r
437                         p.ColumnCount = 2;\r
438                         p.RowCount = 2;\r
439 \r
440                         p.SetColumnSpan (c2, 2);\r
441 \r
442                         p.Controls.Add (c1);\r
443                         p.Controls.Add (c2);\r
444                         p.Controls.Add (c3);\r
445 \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
449                 }\r
450 \r
451                 [Test]\r
452                 public void TestCellPositioning11 ()\r
453                 {\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
459 \r
460                         p.ColumnCount = 2;\r
461                         p.RowCount = 2;\r
462 \r
463                         p.SetRowSpan (c3, 2);\r
464 \r
465                         p.Controls.Add (c1);\r
466                         p.Controls.Add (c2);\r
467                         p.Controls.Add (c3);\r
468 \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
472                 }\r
473 \r
474                 [Test]\r
475                 public void TestCellPositioning12 ()\r
476                 {\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
482 \r
483                         p.ColumnCount = 2;\r
484                         p.RowCount = 2;\r
485 \r
486                         p.SetColumn (c1, 4);\r
487 \r
488                         p.Controls.Add (c1);\r
489                         p.Controls.Add (c2);\r
490                         p.Controls.Add (c3);\r
491 \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
495                 }\r
496 \r
497                 [Test]\r
498                 public void TestCellPositioning13 ()\r
499                 {\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
505 \r
506                         p.ColumnCount = 3;\r
507                         p.RowCount = 2;\r
508 \r
509                         p.SetRowSpan (c3, 2);\r
510 \r
511                         p.Controls.Add (c1);\r
512                         p.Controls.Add (c2);\r
513                         p.Controls.Add (c3);\r
514 \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
518                 }\r
519 \r
520                 [Test]\r
521                 [Category ("NotWorking")]\r
522                 public void TestCellPositioning14 ()\r
523                 {\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
528 \r
529                         p.ColumnCount = 2;\r
530                         p.RowCount = 2;\r
531 \r
532                         p.SetColumnSpan (c1, 3);\r
533 \r
534                         p.Controls.Add (c1);\r
535 \r
536                         Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");\r
537                 }\r
538 \r
539                 [Test]\r
540                 public void TestCellPositioning15 ()\r
541                 {\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
548 \r
549                         p.ColumnCount = 2;\r
550                         p.RowCount = 2;\r
551 \r
552                         p.SetColumnSpan (c2, 2);\r
553                         p.SetCellPosition (c2, new TableLayoutPanelCellPosition (1, 0));\r
554 \r
555                         p.Controls.Add (c1);\r
556                         p.Controls.Add (c2);\r
557                         p.Controls.Add (c3);\r
558 \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
562                 }\r
563 \r
564                 [Test]\r
565                 public void TestCellPositioning16 ()\r
566                 {\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
572 \r
573                         p.ColumnCount = 2;\r
574                         p.RowCount = 2;\r
575 \r
576                         p.SetRowSpan (c3, 2);\r
577                         p.SetCellPosition (c3, new TableLayoutPanelCellPosition (0, 1));\r
578 \r
579                         p.Controls.Add (c1);\r
580                         p.Controls.Add (c2);\r
581                         p.Controls.Add (c3);\r
582 \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
586                 }\r
587 \r
588                 [Test]\r
589                 public void TestCellPositioning17 ()\r
590                 {\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
593                         //\r
594                         TableLayoutPanel p = new TableLayoutPanel ();\r
595                         p.ColumnCount = 0;\r
596                         p.RowCount = 0;\r
597                         Control c1 = new Button ();\r
598 \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
603                 }\r
604 \r
605                 [Test]\r
606                 public void TestCellPositioning18 ()\r
607                 {\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
616 \r
617                         p.ColumnCount = 3;\r
618                         p.RowCount = 4;\r
619 \r
620                         p.SetRowSpan (c1, 2);\r
621                         p.SetColumnSpan (c1, 2);\r
622                         p.SetCellPosition (c1, new TableLayoutPanelCellPosition (0, 0));\r
623 \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
628 \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
633                 }\r
634 \r
635                 [Test]\r
636                 public void TestRowColumnSizes1 ()\r
637                 {\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
643 \r
644                         p.ColumnCount = 2;\r
645                         p.RowCount = 1;\r
646 \r
647                         p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));\r
648 \r
649                         p.Controls.Add (c1);\r
650                         p.Controls.Add (c2);\r
651                         p.Controls.Add (c3);\r
652 \r
653                         Assert.AreEqual (71, p.GetRowHeights ()[0], "D1");\r
654                         Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");\r
655                 }\r
656 \r
657                 [Test]\r
658                 public void TestRowColumnSizes2 ()\r
659                 {\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
665 \r
666                         p.ColumnCount = 2;\r
667                         p.RowCount = 1;\r
668 \r
669                         p.RowStyles.Add (new RowStyle (SizeType.Absolute, 100F));\r
670 \r
671                         p.Controls.Add (c1);\r
672                         p.Controls.Add (c2);\r
673                         p.Controls.Add (c3);\r
674 \r
675                         Assert.AreEqual (100, p.GetRowHeights ()[0], "D1");\r
676                         Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");\r
677                 }\r
678 \r
679                 [Test]\r
680                 public void TestRowColumnSizes3 ()\r
681                 {\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
689 \r
690                         p.ColumnCount = 2;\r
691                         p.RowCount = 1;\r
692 \r
693                         p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));\r
694 \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
700 \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
704                 }\r
705 \r
706                 [Test]\r
707                 public void TestRowColumnSizes4 ()\r
708                 {\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
718 \r
719                         p.ColumnCount = 2;\r
720                         p.RowCount = 1;\r
721 \r
722                         p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));\r
723 \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
731 \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
736                 }\r
737 \r
738                 [Test]\r
739                 public void TestRowColumnSizes5 ()\r
740                 {\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
746 \r
747                         p.ColumnCount = 2;\r
748                         p.RowCount = 2;\r
749 \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
754 \r
755                         p.Controls.Add (c1);\r
756                         p.Controls.Add (c2);\r
757                         p.Controls.Add (c3);\r
758 \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
763                 }\r
764 \r
765                 [Test]\r
766                 public void TestRowColumnSizes6 ()\r
767                 {\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
773 \r
774                         p.ColumnCount = 2;\r
775                         p.RowCount = 2;\r
776 \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
781 \r
782                         p.Controls.Add (c1);\r
783                         p.Controls.Add (c2);\r
784                         p.Controls.Add (c3);\r
785 \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
790                 }\r
791 \r
792                 [Test]\r
793                 public void TestRowColumnSizes7 ()\r
794                 {\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
800 \r
801                         p.ColumnCount = 3;\r
802                         p.RowCount = 3;\r
803 \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
810 \r
811                         p.Controls.Add (c1);\r
812                         p.Controls.Add (c2);\r
813                         p.Controls.Add (c3);\r
814 \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
821                 }\r
822 \r
823                 [Test]\r
824                 public void TestRowColumnSizes8 ()\r
825                 {\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
831 \r
832                         p.ColumnCount = 3;\r
833                         p.RowCount = 3;\r
834 \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
841 \r
842                         p.Controls.Add (c1);\r
843                         p.Controls.Add (c2);\r
844                         p.Controls.Add (c3);\r
845 \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
852                 }\r
853 \r
854                 [Test]\r
855                 public void TestRowColumnSizes9 ()\r
856                 {\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
862 \r
863                         p.ColumnCount = 3;\r
864                         p.RowCount = 3;\r
865 \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
872 \r
873                         p.Controls.Add (c1);\r
874                         p.Controls.Add (c2);\r
875                         p.Controls.Add (c3);\r
876 \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
883                 }\r
884 \r
885                 [Test]\r
886                 public void TestRowColumnSizes10 ()\r
887                 {\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
893 \r
894                         p.ColumnCount = 2;\r
895                         p.RowCount = 2;\r
896 \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
901 \r
902                         p.Controls.Add (c1);\r
903                         p.Controls.Add (c2);\r
904                         p.Controls.Add (c3);\r
905 \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
910                 }\r
911 \r
912                 [Test]\r
913                 public void TestRowColumnSizes11 ()\r
914                 {\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
922 \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
926 \r
927                         p.ColumnCount = 4;\r
928                         p.RowCount = 3;\r
929 \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
937 \r
938                         p.SetColumnSpan (c1, 2);\r
939                         p.SetColumnSpan (c3, 2);\r
940 \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
944 \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
954                 }\r
955                 \r
956                 [Test]\r
957                 public void Bug81843 ()\r
958                 {\r
959                         Form f = new Form ();\r
960                         f.ShowInTaskbar = false;\r
961                         \r
962                         TableLayoutPanel tableLayoutPanel1;\r
963                         Button button2;\r
964                         TextBox textBox1;\r
965                         Button button4;\r
966 \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
973 \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
987 \r
988                         button2.Size = new Size (75, 23);\r
989                         \r
990                         button4.Size = new Size (75, 23);\r
991 \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
996 \r
997                         f.ClientSize = new Size (292, 312);\r
998                         f.Controls.Add (tableLayoutPanel1);\r
999                         f.Name = "Form1";\r
1000                         f.Text = "Form1";\r
1001                         tableLayoutPanel1.ResumeLayout (false);\r
1002                         tableLayoutPanel1.PerformLayout ();\r
1003                         f.ResumeLayout (false);\r
1004                         f.PerformLayout ();\r
1005 \r
1006                         f.Show ();\r
1007 \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
1011                         \r
1012                         f.Dispose ();\r
1013                 }\r
1014                 \r
1015                 [Test]  // From bug #81884\r
1016                 public void CellBorderStyle ()\r
1017                 {\r
1018                         Form f = new Form ();\r
1019                         f.ShowInTaskbar = false;\r
1020 \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
1028                         p.Height = 200;\r
1029                         p.RowCount = 2;\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
1033 \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
1039 \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
1045 \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
1051 \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
1057 \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
1063 \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
1069 \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
1076 \r
1077                         f.Show ();\r
1078                         // None\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
1085                         \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
1093 \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
1101 \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
1109 \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
1117 \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
1125 \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
1133                         \r
1134                         f.Close ();\r
1135                 }\r
1136 \r
1137                 [Test]\r
1138                 public void Bug81936 ()\r
1139                 {\r
1140                         Form f = new Form ();\r
1141                         f.ShowInTaskbar = false;\r
1142 \r
1143                         TableLayoutPanel tableLayoutPanel1;\r
1144                         Label button2;\r
1145                         Label button4;\r
1146 \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
1158 \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
1168 \r
1169                         f.ClientSize = new Size (292, 312);\r
1170                         f.Controls.Add (tableLayoutPanel1);\r
1171                         f.Name = "Form1";\r
1172                         f.Text = "Form1";\r
1173                         tableLayoutPanel1.ResumeLayout (false);\r
1174                         tableLayoutPanel1.PerformLayout ();\r
1175                         f.ResumeLayout (false);\r
1176                         f.PerformLayout ();\r
1177 \r
1178                         f.Show ();\r
1179 \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
1182 \r
1183                         f.Dispose ();\r
1184                 }\r
1185 \r
1186                 [Test]\r
1187                 public void Bug82605 ()\r
1188                 {\r
1189                         Form f = new Form ();\r
1190                         f.ShowInTaskbar = false;\r
1191                         \r
1192                         Label l = new Label ();\r
1193 \r
1194                         TableLayoutPanel table = new TableLayoutPanel ();\r
1195                         table.ColumnCount = 1;\r
1196                         table.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100F));\r
1197 \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
1201 \r
1202                         table.Controls.Add (l, 0, 1);\r
1203                         table.Location = new Point (0, 0);\r
1204                         table.Width = 250;\r
1205 \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
1212 \r
1213                         f.Controls.Add (table);\r
1214                         f.Show ();\r
1215                         \r
1216                         // Height is font dependent, but this bug is about the width anyways\r
1217                         Assert.AreEqual (244, l.Width, "A1");\r
1218 \r
1219                         f.Dispose ();\r
1220                 }\r
1221                 \r
1222                 [Test] // bug #82040\r
1223                 public void ShowNoChildren ()\r
1224                 {\r
1225                         Form form = new Form ();\r
1226                         form.ShowInTaskbar = false;\r
1227 \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
1233 \r
1234                         form.Show ();\r
1235                         form.Refresh ();\r
1236                         form.Dispose ();\r
1237                 }\r
1238 \r
1239                 [Test] // bug #82041\r
1240                 public void DontCallResumeLayout ()\r
1241                 {\r
1242                         Form form = new Form ();\r
1243                         form.ShowInTaskbar = false;\r
1244 \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
1252 \r
1253                         form.Show ();\r
1254                         form.Refresh ();\r
1255                         form.Dispose ();\r
1256                 }\r
1257                 \r
1258                 [Test] // bug #346246\r
1259                 public void AutoSizePanelVertical ()\r
1260                 {\r
1261                         Form f = new Form ();\r
1262                         f.ShowInTaskbar = false;\r
1263                         \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
1271                         tlp.RowCount = 2;\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
1275                         tlp.TabIndex = 0;\r
1276 \r
1277                         f.Controls.Add (tlp);\r
1278 \r
1279                         Button b = new Button ();\r
1280                         b.Size = new Size (100, 100);\r
1281                         tlp.Controls.Add (b, 0, 0);\r
1282 \r
1283                         PictureBox p = new PictureBox ();\r
1284                         p.Size = new Size (100, 100);\r
1285                         tlp.Controls.Add (p,0,1);\r
1286                         \r
1287                         f.Show ();\r
1288 \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
1292                         \r
1293                         b.Width += 20;\r
1294                         b.Height += 20;\r
1295 \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
1299 \r
1300                         p.Width += 20;\r
1301                         p.Height += 20;\r
1302 \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
1306                         \r
1307                         f.Dispose ();\r
1308                 }\r
1309 \r
1310                 [Test] // bug #346246\r
1311                 public void AutoSizePanelHorizontal ()\r
1312                 {\r
1313                         Form f = new Form ();\r
1314                         f.ShowInTaskbar = false;\r
1315 \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
1324                         tlp.RowCount = 1;\r
1325                         tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));\r
1326                         tlp.Size = new Size (139, 182);\r
1327                         tlp.TabIndex = 0;\r
1328 \r
1329                         f.Controls.Add (tlp);\r
1330 \r
1331                         Button b = new Button ();\r
1332                         b.Size = new Size (100, 100);\r
1333                         tlp.Controls.Add (b, 0, 0);\r
1334 \r
1335                         PictureBox p = new PictureBox ();\r
1336                         p.Size = new Size (100, 100);\r
1337                         tlp.Controls.Add (p, 1, 0);\r
1338 \r
1339                         f.Show ();\r
1340 \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
1344 \r
1345                         b.Width += 20;\r
1346                         b.Height += 20;\r
1347 \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
1351 \r
1352                         p.Width += 20;\r
1353                         p.Height += 20;\r
1354 \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
1358 \r
1359                         f.Dispose ();\r
1360                 }\r
1361                 \r
1362                 [Test]\r
1363                 public void Bug354676 ()\r
1364                 {\r
1365                         Form f = new Form ();\r
1366 \r
1367                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1368                         tlp.Dock = DockStyle.Fill;\r
1369                         tlp.Padding = new Padding (40);\r
1370                         tlp.RowCount = 2;\r
1371                         tlp.ColumnCount = 1;\r
1372                         f.Controls.Add (tlp);\r
1373 \r
1374                         Button b1 = new Button ();\r
1375                         tlp.Controls.Add (b1);\r
1376 \r
1377                         Button b2 = new Button ();\r
1378                         tlp.Controls.Add (b2);\r
1379 \r
1380                         f.Show ();\r
1381 \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
1384                         \r
1385                         f.Close ();\r
1386                         f.Dispose ();\r
1387                 }\r
1388                 \r
1389                 [Test]\r
1390                 public void Bug355408 ()\r
1391                 {\r
1392                         Form f = new Form ();\r
1393                         f.ClientSize = new Size (300, 300);\r
1394                         \r
1395                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1396                         tlp.Dock = DockStyle.Fill;\r
1397                         tlp.RowCount = 2;\r
1398                         tlp.ColumnCount = 2;\r
1399                         f.Controls.Add (tlp);\r
1400 \r
1401                         Button b1 = new Button ();\r
1402                         tlp.Controls.Add (b1);\r
1403 \r
1404                         Button b2 = new Button ();\r
1405                         tlp.Controls.Add (b2);\r
1406                         \r
1407                         Button b3 = new Button ();\r
1408                         b3.Dock = DockStyle.Fill;\r
1409                         b3.Width = 250;\r
1410                         tlp.SetColumnSpan (b3, 2);\r
1411                         tlp.Controls.Add (b3);\r
1412 \r
1413                         f.Show ();\r
1414 \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
1418 \r
1419                         f.Close ();\r
1420                         f.Dispose ();\r
1421                 }\r
1422                 \r
1423                 [Test]\r
1424                 public void Bug402651 ()\r
1425                 {\r
1426                         Form f = new Form ();\r
1427                         f.ClientSize = new Size (300, 300);\r
1428 \r
1429                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1430                         tlp.Dock = DockStyle.Fill;\r
1431                         tlp.RowCount = 2;\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
1435 \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
1440 \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
1448 \r
1449                         f.Show ();\r
1450 \r
1451                         b2.Visible = true;\r
1452                         Assert.AreEqual (new Size (100, 100), b2.Size, "A1");\r
1453 \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
1458 \r
1459                         f.Dispose ();\r
1460                 }\r
1461 \r
1462                 [Test]\r
1463                 public void Bug354672 ()\r
1464                 {\r
1465                         Form f = new Form ();\r
1466                         f.ClientSize = new Size (300, 300);\r
1467 \r
1468                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1469                         tlp.AutoSize = true;\r
1470                         tlp.ColumnCount = 2;\r
1471                         tlp.RowCount = 1;\r
1472                         f.Controls.Add (tlp);\r
1473 \r
1474                         TextBox t1 = new TextBox ();\r
1475                         t1.Dock = DockStyle.Fill;\r
1476                         tlp.Controls.Add (t1);\r
1477 \r
1478                         TextBox t2 = new TextBox ();\r
1479                         t2.Dock = DockStyle.Fill;\r
1480                         tlp.Controls.Add (t2);\r
1481 \r
1482                         Assert.AreEqual (new Size (212, t1.Height + 6), tlp.PreferredSize, "A1");\r
1483 \r
1484                         f.Dispose ();\r
1485                 }\r
1486 \r
1487                 [Test]\r
1488                 public void Bug354672More ()\r
1489                 {\r
1490                         Form f = new Form ();\r
1491                         f.ClientSize = new Size (300, 300);\r
1492 \r
1493                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1494                         tlp.AutoSize = true;\r
1495                         tlp.ColumnCount = 2;\r
1496                         tlp.RowCount = 1;\r
1497                         tlp.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));\r
1498                         tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50f));\r
1499                         \r
1500                         f.Controls.Add (tlp);\r
1501 \r
1502                         TextBox t1 = new TextBox ();\r
1503                         t1.Dock = DockStyle.Fill;\r
1504                         tlp.Controls.Add (t1);\r
1505 \r
1506                         TextBox t2 = new TextBox ();\r
1507                         t2.Dock = DockStyle.Fill;\r
1508                         tlp.Controls.Add (t2);\r
1509 \r
1510                         Assert.AreEqual (new Size (212, t1.Height + 6), tlp.PreferredSize, "A1");\r
1511 \r
1512                         f.Dispose ();\r
1513                 }\r
1514                 \r
1515                 [Test]\r
1516                 public void Bug367249 ()\r
1517                 {\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
1523 \r
1524                         Button OkButton = new Button ();\r
1525                         OkButton.Text = "OK";\r
1526                         LayoutPanel.Controls.Add (OkButton);\r
1527                         LayoutPanel.SetColumnSpan (OkButton, 3);\r
1528                 }\r
1529                 \r
1530                 [Test]\r
1531                 public void Bug396141 ()\r
1532                 {\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
1536 \r
1537                         Form f = new Form ();\r
1538                         f.ClientSize = new Size (300, 300);\r
1539                         f.ShowInTaskbar = false;\r
1540 \r
1541                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1542                         tlp.AutoSize = true;\r
1543                         tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;\r
1544                         tlp.ColumnCount = 2;\r
1545                         tlp.RowCount = 0;\r
1546 \r
1547                         f.Controls.Add (tlp);\r
1548 \r
1549                         TextBox t1 = new TextBox ();\r
1550                         t1.Dock = DockStyle.Fill;\r
1551                         tlp.Controls.Add (t1);\r
1552 \r
1553                         TextBox t2 = new TextBox ();\r
1554                         t2.Dock = DockStyle.Fill;\r
1555                         tlp.Controls.Add (t2);\r
1556 \r
1557                         f.Show ();\r
1558                         \r
1559                         Assert.IsTrue (tlp.Height > 0, "Height must be > 0");\r
1560                         Assert.IsTrue (tlp.Width > 0, "Width must be > 0");\r
1561 \r
1562                         f.Dispose ();\r
1563                 }\r
1564                 \r
1565                 [Test]\r
1566                 public void Bug396433 ()\r
1567                 {\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
1573 \r
1574                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1575                         tlp.AutoSize = true;\r
1576                         tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;\r
1577                         tlp.ColumnCount = 2;\r
1578                         tlp.RowCount = 1;\r
1579 \r
1580                         f.Controls.Add (tlp);\r
1581 \r
1582                         Button t1 = new Button ();\r
1583                         tlp.Controls.Add (t1);\r
1584 \r
1585                         Button t2 = new Button ();\r
1586                         tlp.Controls.Add (t2);\r
1587 \r
1588                         f.Show ();\r
1589 \r
1590                         Assert.AreEqual (new Size (162, 29), tlp.PreferredSize, "A1");\r
1591                         \r
1592                         tlp.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;\r
1593 \r
1594                         Assert.AreEqual (new Size (165, 31), tlp.PreferredSize, "A2");\r
1595 \r
1596                         f.Dispose ();\r
1597                 }\r
1598                 \r
1599                 [Test]\r
1600                 public void IgnoreAutoSizeMode ()\r
1601                 {\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
1607 \r
1608                         TableLayoutPanel tlp = new TableLayoutPanel ();\r
1609                         tlp.AutoSize = true;\r
1610                         tlp.Dock = DockStyle.Top;\r
1611                         tlp.ColumnCount = 1;\r
1612                         tlp.RowCount = 1;\r
1613 \r
1614                         f.Controls.Add (tlp);\r
1615 \r
1616                         Button t1 = new Button ();\r
1617                         tlp.Controls.Add (t1);\r
1618 \r
1619                         f.Show ();\r
1620 \r
1621                         Assert.AreEqual (29, tlp.Height, "A1");\r
1622 \r
1623                         tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;\r
1624 \r
1625                         Assert.AreEqual (29, tlp.Height, "A2");\r
1626 \r
1627                         f.Dispose ();\r
1628                 }\r
1629 \r
1630                 [Test]\r
1631                 public void TestTableLayoutStyleOwned ()\r
1632                 {\r
1633                         try {\r
1634                                 ColumnStyle style = new ColumnStyle ();\r
1635                                 TableLayoutColumnStyleCollection coll = new TableLayoutPanel ().ColumnStyles;\r
1636                                 coll.Add (style);\r
1637                                 TableLayoutColumnStyleCollection coll2 = new TableLayoutPanel ().ColumnStyles;\r
1638                                 coll2.Add (style);\r
1639                                 Assert.Fail ("#1");\r
1640                         } catch (ArgumentException ex) {\r
1641                                 // PASS\r
1642                         }\r
1643 \r
1644                         try {\r
1645                                 RowStyle style = new RowStyle ();\r
1646                                 TableLayoutRowStyleCollection coll = new TableLayoutPanel ().RowStyles;\r
1647                                 coll.Add (style);\r
1648                                 TableLayoutRowStyleCollection coll2 = new TableLayoutPanel ().RowStyles;\r
1649                                 coll2.Add (style);\r
1650                                 Assert.Fail ("#2");\r
1651                         } catch (ArgumentException ex) {\r
1652                                 // PASS\r
1653                         }\r
1654                 }\r
1655 \r
1656                 [Test] // Novell bug #497562\r
1657                 public void TestLayoutSettingsSetter ()\r
1658                 {\r
1659                         using (var tlp = new TableLayoutPanel ()) {\r
1660                                 TableLayoutSettings tls;\r
1661 \r
1662                                 using (var ms = new MemoryStream ()) {\r
1663                                         var formatter = new BinaryFormatter ();\r
1664                                         formatter.Serialize (ms, tlp.LayoutSettings);\r
1665 \r
1666                                         ms.Position = 0;\r
1667 \r
1668                                         tls = (TableLayoutSettings) formatter.Deserialize (ms);\r
1669                                 }\r
1670 \r
1671                                 tlp.LayoutSettings = tls;\r
1672                                 tlp.LayoutSettings = tls; // Should not throw an exception\r
1673                         }\r
1674                 }\r
1675         }\r
1676 }\r
1677 #endif\r