TableLayoutTest.cs 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579
  1. //
  2. // TableLayoutTests.cs
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. // Copyright (c) 2006 Jonathan Pobst
  24. //
  25. // Authors:
  26. // Jonathan Pobst ([email protected])
  27. //
  28. #if NET_2_0
  29. using System;
  30. using System.Drawing;
  31. using System.Windows.Forms;
  32. using NUnit.Framework;
  33. namespace MonoTests.System.Windows.Forms
  34. {
  35. [TestFixture]
  36. public class TableLayoutTests : TestHelper
  37. {
  38. [Test]
  39. public void TestConstruction ()
  40. {
  41. TableLayoutPanel p = new TableLayoutPanel ();
  42. Assert.AreEqual (BorderStyle.None, p.BorderStyle, "A1");
  43. Assert.AreEqual (TableLayoutPanelCellBorderStyle.None, p.CellBorderStyle, "A2");
  44. Assert.AreEqual (0, p.ColumnCount, "A3");
  45. Assert.AreEqual (TableLayoutPanelGrowStyle.AddRows, p.GrowStyle, "A4");
  46. Assert.AreEqual ("System.Windows.Forms.Layout.TableLayout", p.LayoutEngine.ToString (), "A5");
  47. Assert.AreEqual ("System.Windows.Forms.TableLayoutSettings", p.LayoutSettings.ToString (), "A6");
  48. Assert.AreEqual (0, p.RowCount, "A7");
  49. Assert.AreEqual (0, p.ColumnStyles.Count, "A8");
  50. Assert.AreEqual (0, p.RowStyles.Count, "A9");
  51. Assert.AreEqual (new Size (200, 100), p.Size, "A10");
  52. }
  53. [Test]
  54. public void TestPropertySetters ()
  55. {
  56. TableLayoutPanel p = new TableLayoutPanel ();
  57. p.BorderStyle = BorderStyle.Fixed3D;
  58. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;
  59. p.ColumnCount = 1;
  60. p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;
  61. p.RowCount = 1;
  62. Assert.AreEqual (BorderStyle.Fixed3D, p.BorderStyle, "A1");
  63. Assert.AreEqual (TableLayoutPanelCellBorderStyle.OutsetDouble, p.CellBorderStyle, "A2");
  64. Assert.AreEqual (1, p.ColumnCount, "A3");
  65. Assert.AreEqual (TableLayoutPanelGrowStyle.FixedSize, p.GrowStyle, "A4");
  66. Assert.AreEqual (1, p.RowCount, "A7");
  67. }
  68. [Test]
  69. public void TestExtenderMethods ()
  70. {
  71. TableLayoutPanel p = new TableLayoutPanel ();
  72. Control c = new Button ();
  73. Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetCellPosition (c), "A1");
  74. Assert.AreEqual (-1, p.GetColumn (c), "A2");
  75. Assert.AreEqual (1, p.GetColumnSpan (c), "A3");
  76. Assert.AreEqual (-1, p.GetRow (c), "A4");
  77. Assert.AreEqual (1, p.GetRowSpan (c), "A5");
  78. p.SetCellPosition (c, new TableLayoutPanelCellPosition (1, 1));
  79. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetCellPosition (c), "A6");
  80. p.SetColumn (c, 2);
  81. Assert.AreEqual (2, p.GetColumn (c), "A7");
  82. p.SetRow (c, 2);
  83. Assert.AreEqual (2, p.GetRow (c), "A9");
  84. p.SetColumnSpan (c, 2);
  85. Assert.AreEqual (2, p.GetColumnSpan (c), "A8");
  86. p.SetRowSpan (c, 2);
  87. Assert.AreEqual (2, p.GetRowSpan (c), "A10");
  88. Assert.AreEqual (new TableLayoutPanelCellPosition (2, 2), p.GetCellPosition (c), "A11");
  89. // ???????
  90. //Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetPositionFromControl (c), "A12");
  91. //Assert.AreEqual (c, p.GetControlFromPosition(0, 0), "A13");
  92. }
  93. [Test]
  94. public void TestColumnStyles ()
  95. {
  96. TableLayoutPanel p = new TableLayoutPanel ();
  97. p.ColumnStyles.Add (new ColumnStyle ());
  98. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute));
  99. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 20F));
  100. Assert.AreEqual (3, p.ColumnStyles.Count, "A1");
  101. Assert.AreEqual (SizeType.AutoSize, p.ColumnStyles[0].SizeType, "A2");
  102. Assert.AreEqual (0, p.ColumnStyles[0].Width, "A3");
  103. Assert.AreEqual (SizeType.Absolute, p.ColumnStyles[1].SizeType, "A4");
  104. Assert.AreEqual (0, p.ColumnStyles[1].Width, "A5");
  105. Assert.AreEqual (SizeType.Percent, p.ColumnStyles[2].SizeType, "A6");
  106. Assert.AreEqual (20F, p.ColumnStyles[2].Width, "A7");
  107. p.ColumnStyles.Remove (p.ColumnStyles[0]);
  108. Assert.AreEqual (2, p.ColumnStyles.Count, "A8");
  109. Assert.AreEqual (SizeType.Absolute, p.ColumnStyles[0].SizeType, "A9");
  110. Assert.AreEqual (0, p.ColumnStyles[0].Width, "A10");
  111. Assert.AreEqual (SizeType.Percent, p.ColumnStyles[1].SizeType, "A11");
  112. Assert.AreEqual (20F, p.ColumnStyles[1].Width, "A12");
  113. }
  114. [Test]
  115. public void TestRowStyles ()
  116. {
  117. TableLayoutPanel p = new TableLayoutPanel ();
  118. p.RowStyles.Add (new RowStyle ());
  119. p.RowStyles.Add (new RowStyle (SizeType.Absolute));
  120. p.RowStyles.Add (new RowStyle (SizeType.Percent, 20F));
  121. Assert.AreEqual (3, p.RowStyles.Count, "A1");
  122. Assert.AreEqual (SizeType.AutoSize, p.RowStyles[0].SizeType, "A2");
  123. Assert.AreEqual (0, p.RowStyles[0].Height, "A3");
  124. Assert.AreEqual (SizeType.Absolute, p.RowStyles[1].SizeType, "A4");
  125. Assert.AreEqual (0, p.RowStyles[1].Height, "A5");
  126. Assert.AreEqual (SizeType.Percent, p.RowStyles[2].SizeType, "A6");
  127. Assert.AreEqual (20F, p.RowStyles[2].Height, "A7");
  128. p.RowStyles.Remove (p.RowStyles[0]);
  129. Assert.AreEqual (2, p.RowStyles.Count, "A8");
  130. Assert.AreEqual (SizeType.Absolute, p.RowStyles[0].SizeType, "A9");
  131. Assert.AreEqual (0, p.RowStyles[0].Height, "A10");
  132. Assert.AreEqual (SizeType.Percent, p.RowStyles[1].SizeType, "A11");
  133. Assert.AreEqual (20F, p.RowStyles[1].Height, "A12");
  134. }
  135. [Test]
  136. public void TestColumnStyles3 ()
  137. {
  138. // Don't lose the 2nd style
  139. TableLayoutPanel p = new TableLayoutPanel ();
  140. p.ColumnCount = 2;
  141. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));
  142. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));
  143. p.ColumnCount = 1;
  144. Assert.AreEqual (2, p.ColumnStyles.Count, "A1");
  145. }
  146. [Test]
  147. public void TestColumnStyles2 ()
  148. {
  149. // Don't lose the 2nd style
  150. TableLayoutPanel p = new TableLayoutPanel ();
  151. p.ColumnCount = 1;
  152. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));
  153. p.ColumnCount = 2;
  154. Assert.AreEqual (1, p.ColumnStyles.Count, "A2");
  155. }
  156. [Test]
  157. public void TestCellPositioning ()
  158. {
  159. // Standard Add
  160. TableLayoutPanel p = new TableLayoutPanel ();
  161. Control c1 = new Button ();
  162. Control c2 = new Button ();
  163. Control c3 = new Button ();
  164. Control c4 = new Button ();
  165. p.ColumnCount = 2;
  166. p.RowCount = 2;
  167. p.Controls.Add (c1);
  168. p.Controls.Add (c2);
  169. p.Controls.Add (c3);
  170. p.Controls.Add (c4);
  171. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  172. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
  173. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
  174. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c4), "C4");
  175. }
  176. [Test]
  177. public void TestCellPositioning2 ()
  178. {
  179. // Growstyle = Add Rows
  180. TableLayoutPanel p = new TableLayoutPanel ();
  181. Control c1 = new Button ();
  182. Control c2 = new Button ();
  183. Control c3 = new Button ();
  184. Control c4 = new Button ();
  185. Control c5 = new Button ();
  186. Control c6 = new Button ();
  187. p.ColumnCount = 2;
  188. p.RowCount = 2;
  189. p.Controls.Add (c1);
  190. p.Controls.Add (c2);
  191. p.Controls.Add (c3);
  192. p.Controls.Add (c4);
  193. p.Controls.Add (c5);
  194. p.Controls.Add (c6);
  195. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  196. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
  197. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
  198. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c4), "C4");
  199. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 2), p.GetPositionFromControl (c5), "C5");
  200. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 2), p.GetPositionFromControl (c6), "C6");
  201. }
  202. [Test]
  203. public void TestCellPositioning3 ()
  204. {
  205. // Growstyle = Add Columns
  206. TableLayoutPanel p = new TableLayoutPanel ();
  207. p.GrowStyle = TableLayoutPanelGrowStyle.AddColumns;
  208. Control c1 = new Button ();
  209. Control c2 = new Button ();
  210. Control c3 = new Button ();
  211. Control c4 = new Button ();
  212. Control c5 = new Button ();
  213. Control c6 = new Button ();
  214. p.ColumnCount = 2;
  215. p.RowCount = 2;
  216. p.Controls.Add (c1);
  217. p.Controls.Add (c2);
  218. p.Controls.Add (c3);
  219. p.Controls.Add (c4);
  220. p.Controls.Add (c5);
  221. p.Controls.Add (c6);
  222. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  223. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
  224. Assert.AreEqual (new TableLayoutPanelCellPosition (2, 0), p.GetPositionFromControl (c3), "C3");
  225. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c4), "C4");
  226. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c5), "C5");
  227. Assert.AreEqual (new TableLayoutPanelCellPosition (2, 1), p.GetPositionFromControl (c6), "C6");
  228. }
  229. [Test]
  230. [ExpectedException (typeof (ArgumentException))]
  231. public void TestCellPositioning4 ()
  232. {
  233. // Growstyle = Fixed Size
  234. TableLayoutPanel p = new TableLayoutPanel ();
  235. p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;
  236. Control c1 = new Button ();
  237. Control c2 = new Button ();
  238. Control c3 = new Button ();
  239. Control c4 = new Button ();
  240. Control c5 = new Button ();
  241. p.ColumnCount = 2;
  242. p.RowCount = 2;
  243. p.Controls.Add (c1);
  244. p.Controls.Add (c2);
  245. p.Controls.Add (c3);
  246. p.Controls.Add (c4);
  247. p.Controls.Add (c5);
  248. }
  249. [Test]
  250. public void TestCellPositioning5 ()
  251. {
  252. // One control have fixed position
  253. TableLayoutPanel p = new TableLayoutPanel ();
  254. Control c1 = new Button ();
  255. Control c2 = new Button ();
  256. Control c3 = new Button ();
  257. Control c4 = new Button ();
  258. p.ColumnCount = 2;
  259. p.RowCount = 2;
  260. p.SetCellPosition (c4, new TableLayoutPanelCellPosition (0, 0));
  261. p.Controls.Add (c1);
  262. p.Controls.Add (c2);
  263. p.Controls.Add (c3);
  264. p.Controls.Add (c4);
  265. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c4), "C1");
  266. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c1), "C2");
  267. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c2), "C3");
  268. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c3), "C4");
  269. }
  270. [Test]
  271. public void TestCellPositioning6 ()
  272. {
  273. // One control has fixed column, it should be ignored
  274. TableLayoutPanel p = new TableLayoutPanel ();
  275. Control c1 = new Button ();
  276. Control c2 = new Button ();
  277. Control c3 = new Button ();
  278. Control c4 = new Button ();
  279. p.ColumnCount = 2;
  280. p.RowCount = 2;
  281. p.SetColumn (c3, 1);
  282. p.Controls.Add (c1);
  283. p.Controls.Add (c2);
  284. p.Controls.Add (c3);
  285. p.Controls.Add (c4);
  286. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  287. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
  288. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
  289. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c4), "C4");
  290. }
  291. [Test]
  292. public void TestCellPositioning7 ()
  293. {
  294. // One control has fixed column and row
  295. TableLayoutPanel p = new TableLayoutPanel ();
  296. Control c1 = new Button ();
  297. Control c2 = new Button ();
  298. Control c3 = new Button ();
  299. Control c4 = new Button ();
  300. p.ColumnCount = 2;
  301. p.RowCount = 2;
  302. p.SetColumn (c3, 1);
  303. p.SetRow (c3, 1);
  304. p.Controls.Add (c1);
  305. p.Controls.Add (c2);
  306. p.Controls.Add (c3);
  307. p.Controls.Add (c4);
  308. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  309. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
  310. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c3), "C3");
  311. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c4), "C4");
  312. }
  313. [Test]
  314. public void TestCellPositioning8 ()
  315. {
  316. // Column span
  317. TableLayoutPanel p = new TableLayoutPanel ();
  318. Control c1 = new Button ();
  319. Control c2 = new Button ();
  320. Control c3 = new Button ();
  321. p.ColumnCount = 2;
  322. p.RowCount = 2;
  323. p.SetColumnSpan (c1, 2);
  324. p.Controls.Add (c1);
  325. p.Controls.Add (c2);
  326. p.Controls.Add (c3);
  327. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  328. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c2), "C2");
  329. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c3), "C3");
  330. }
  331. [Test]
  332. public void TestCellPositioning9 ()
  333. {
  334. // Row span
  335. TableLayoutPanel p = new TableLayoutPanel ();
  336. Control c1 = new Button ();
  337. Control c2 = new Button ();
  338. Control c3 = new Button ();
  339. p.ColumnCount = 2;
  340. p.RowCount = 2;
  341. p.SetRowSpan (c1, 2);
  342. p.Controls.Add (c1);
  343. p.Controls.Add (c2);
  344. p.Controls.Add (c3);
  345. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  346. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
  347. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c3), "C3");
  348. }
  349. [Test]
  350. public void TestCellPositioning10 ()
  351. {
  352. // Column span = 2, but control is in the last column, forces control back into 1st column, next row
  353. // I have no clue why c3 shouldn't be in (1,0), but MS says it's not
  354. TableLayoutPanel p = new TableLayoutPanel ();
  355. Control c1 = new Button ();
  356. Control c2 = new Button ();
  357. Control c3 = new Button ();
  358. p.ColumnCount = 2;
  359. p.RowCount = 2;
  360. p.SetColumnSpan (c2, 2);
  361. p.Controls.Add (c1);
  362. p.Controls.Add (c2);
  363. p.Controls.Add (c3);
  364. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  365. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c2), "C2");
  366. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 2), p.GetPositionFromControl (c3), "C3");
  367. }
  368. [Test]
  369. public void TestCellPositioning11 ()
  370. {
  371. // Row span = 2, but control is in the last row, creates new row
  372. TableLayoutPanel p = new TableLayoutPanel ();
  373. Control c1 = new Button ();
  374. Control c2 = new Button ();
  375. Control c3 = new Button ();
  376. p.ColumnCount = 2;
  377. p.RowCount = 2;
  378. p.SetRowSpan (c3, 2);
  379. p.Controls.Add (c1);
  380. p.Controls.Add (c2);
  381. p.Controls.Add (c3);
  382. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  383. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
  384. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
  385. }
  386. [Test]
  387. public void TestCellPositioning12 ()
  388. {
  389. // Requesting a column greater than ColumnCount, request is ignored
  390. TableLayoutPanel p = new TableLayoutPanel ();
  391. Control c1 = new Button ();
  392. Control c2 = new Button ();
  393. Control c3 = new Button ();
  394. p.ColumnCount = 2;
  395. p.RowCount = 2;
  396. p.SetColumn (c1, 4);
  397. p.Controls.Add (c1);
  398. p.Controls.Add (c2);
  399. p.Controls.Add (c3);
  400. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  401. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
  402. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
  403. }
  404. [Test]
  405. public void TestCellPositioning13 ()
  406. {
  407. // Row span = 2, but control is in the last row, creates new row
  408. TableLayoutPanel p = new TableLayoutPanel ();
  409. Control c1 = new Button ();
  410. Control c2 = new Button ();
  411. Control c3 = new Button ();
  412. p.ColumnCount = 3;
  413. p.RowCount = 2;
  414. p.SetRowSpan (c3, 2);
  415. p.Controls.Add (c1);
  416. p.Controls.Add (c2);
  417. p.Controls.Add (c3);
  418. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  419. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
  420. Assert.AreEqual (new TableLayoutPanelCellPosition (2, 0), p.GetPositionFromControl (c3), "C3");
  421. }
  422. [Test]
  423. [Category ("NotWorking")]
  424. public void TestCellPositioning14 ()
  425. {
  426. // Col span = 3, fixed grow style
  427. TableLayoutPanel p = new TableLayoutPanel ();
  428. p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;
  429. Control c1 = new Button ();
  430. p.ColumnCount = 2;
  431. p.RowCount = 2;
  432. p.SetColumnSpan (c1, 3);
  433. p.Controls.Add (c1);
  434. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  435. }
  436. [Test]
  437. public void TestCellPositioning15 ()
  438. {
  439. // Column span = 2, but control is in the last column, forces control back into 1st column, next row
  440. // I have no clue why c3 shouldn't be in (1,0), but MS says it's not
  441. TableLayoutPanel p = new TableLayoutPanel ();
  442. Control c1 = new Button ();
  443. Control c2 = new Button ();
  444. Control c3 = new Button ();
  445. p.ColumnCount = 2;
  446. p.RowCount = 2;
  447. p.SetColumnSpan (c2, 2);
  448. p.SetCellPosition (c2, new TableLayoutPanelCellPosition (1, 0));
  449. p.Controls.Add (c1);
  450. p.Controls.Add (c2);
  451. p.Controls.Add (c3);
  452. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  453. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c2), "C2");
  454. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 2), p.GetPositionFromControl (c3), "C3");
  455. }
  456. [Test]
  457. public void TestCellPositioning16 ()
  458. {
  459. // Row span = 2, but control is in the last row, creates new row
  460. TableLayoutPanel p = new TableLayoutPanel ();
  461. Control c1 = new Button ();
  462. Control c2 = new Button ();
  463. Control c3 = new Button ();
  464. p.ColumnCount = 2;
  465. p.RowCount = 2;
  466. p.SetRowSpan (c3, 2);
  467. p.SetCellPosition (c3, new TableLayoutPanelCellPosition (0, 1));
  468. p.Controls.Add (c1);
  469. p.Controls.Add (c2);
  470. p.Controls.Add (c3);
  471. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
  472. Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
  473. Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
  474. }
  475. [Test]
  476. public void TestCellPositioning17 ()
  477. {
  478. // ColumnCount == RowCount == 0, but control is added at > 0.
  479. // The columns and rows are created, but ColumnCount and RowCount remains 0
  480. //
  481. TableLayoutPanel p = new TableLayoutPanel ();
  482. p.ColumnCount = 0;
  483. p.RowCount = 0;
  484. Control c1 = new Button ();
  485. p.Controls.Add (c1, 6, 7);
  486. Assert.AreEqual (new TableLayoutPanelCellPosition (6, 7), p.GetPositionFromControl (c1), "C1");
  487. Assert.AreEqual (0, p.LayoutSettings.ColumnCount, "C2");
  488. Assert.AreEqual (0, p.LayoutSettings.RowCount, "C3");
  489. }
  490. [Test]
  491. public void TestRowColumnSizes1 ()
  492. {
  493. // Row span = 2, but control is in the last row, creates new row
  494. TableLayoutPanel p = new TableLayoutPanel ();
  495. Control c1 = new Button ();
  496. Control c2 = new Button ();
  497. Control c3 = new Button ();
  498. p.ColumnCount = 2;
  499. p.RowCount = 1;
  500. p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
  501. p.Controls.Add (c1);
  502. p.Controls.Add (c2);
  503. p.Controls.Add (c3);
  504. Assert.AreEqual (71, p.GetRowHeights ()[0], "D1");
  505. Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
  506. }
  507. [Test]
  508. public void TestRowColumnSizes2 ()
  509. {
  510. // Row span = 2, but control is in the last row, creates new row
  511. TableLayoutPanel p = new TableLayoutPanel ();
  512. Control c1 = new Button ();
  513. Control c2 = new Button ();
  514. Control c3 = new Button ();
  515. p.ColumnCount = 2;
  516. p.RowCount = 1;
  517. p.RowStyles.Add (new RowStyle (SizeType.Absolute, 100F));
  518. p.Controls.Add (c1);
  519. p.Controls.Add (c2);
  520. p.Controls.Add (c3);
  521. Assert.AreEqual (100, p.GetRowHeights ()[0], "D1");
  522. Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
  523. }
  524. [Test]
  525. public void TestRowColumnSizes3 ()
  526. {
  527. // Row span = 2, but control is in the last row, creates new row
  528. TableLayoutPanel p = new TableLayoutPanel ();
  529. Control c1 = new Button ();
  530. Control c2 = new Button ();
  531. Control c3 = new Button ();
  532. Control c4 = new Button ();
  533. Control c5 = new Button ();
  534. p.ColumnCount = 2;
  535. p.RowCount = 1;
  536. p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
  537. p.Controls.Add (c1);
  538. p.Controls.Add (c2);
  539. p.Controls.Add (c3);
  540. p.Controls.Add (c4);
  541. p.Controls.Add (c5);
  542. Assert.AreEqual (42, p.GetRowHeights ()[0], "D1");
  543. Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
  544. Assert.AreEqual (29, p.GetRowHeights ()[2], "D3");
  545. }
  546. [Test]
  547. public void TestRowColumnSizes4 ()
  548. {
  549. // Row span = 2, but control is in the last row, creates new row
  550. TableLayoutPanel p = new TableLayoutPanel ();
  551. Control c1 = new Button ();
  552. Control c2 = new Button ();
  553. Control c3 = new Button ();
  554. Control c4 = new Button ();
  555. Control c5 = new Button ();
  556. Control c6 = new Button ();
  557. Control c7 = new Button ();
  558. p.ColumnCount = 2;
  559. p.RowCount = 1;
  560. p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
  561. p.Controls.Add (c1);
  562. p.Controls.Add (c2);
  563. p.Controls.Add (c3);
  564. p.Controls.Add (c4);
  565. p.Controls.Add (c5);
  566. p.Controls.Add (c6);
  567. p.Controls.Add (c7);
  568. //Assert.AreEqual (100, p.GetRowHeights ()[0], "D1");
  569. Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
  570. Assert.AreEqual (29, p.GetRowHeights ()[2], "D3");
  571. Assert.AreEqual (29, p.GetRowHeights ()[3], "D4");
  572. }
  573. [Test]
  574. public void TestRowColumnSizes5 ()
  575. {
  576. // 2 Absolute Columns/Rows
  577. TableLayoutPanel p = new TableLayoutPanel ();
  578. Control c1 = new Button ();
  579. Control c2 = new Button ();
  580. Control c3 = new Button ();
  581. p.ColumnCount = 2;
  582. p.RowCount = 2;
  583. p.RowStyles.Add (new RowStyle (SizeType.Absolute, 20));
  584. p.RowStyles.Add (new RowStyle (SizeType.Absolute, 30));
  585. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20));
  586. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 30));
  587. p.Controls.Add (c1);
  588. p.Controls.Add (c2);
  589. p.Controls.Add (c3);
  590. Assert.AreEqual (20, p.GetRowHeights ()[0], "D1");
  591. Assert.AreEqual (80, p.GetRowHeights ()[1], "D2");
  592. Assert.AreEqual (20, p.GetColumnWidths ()[0], "D3");
  593. Assert.AreEqual (180, p.GetColumnWidths ()[1], "D4");
  594. }
  595. [Test]
  596. public void TestRowColumnSizes6 ()
  597. {
  598. // 2 50% Columns/Rows
  599. TableLayoutPanel p = new TableLayoutPanel ();
  600. Control c1 = new Button ();
  601. Control c2 = new Button ();
  602. Control c3 = new Button ();
  603. p.ColumnCount = 2;
  604. p.RowCount = 2;
  605. p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
  606. p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
  607. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
  608. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
  609. p.Controls.Add (c1);
  610. p.Controls.Add (c2);
  611. p.Controls.Add (c3);
  612. Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
  613. Assert.AreEqual (50, p.GetRowHeights ()[1], "D2");
  614. Assert.AreEqual (100, p.GetColumnWidths ()[0], "D3");
  615. Assert.AreEqual (100, p.GetColumnWidths ()[1], "D4");
  616. }
  617. [Test]
  618. public void TestRowColumnSizes7 ()
  619. {
  620. // 1 Absolute and 2 Percent Columns/Rows
  621. TableLayoutPanel p = new TableLayoutPanel ();
  622. Control c1 = new Button ();
  623. Control c2 = new Button ();
  624. Control c3 = new Button ();
  625. p.ColumnCount = 3;
  626. p.RowCount = 3;
  627. p.RowStyles.Add (new RowStyle (SizeType.Absolute, 50));
  628. p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
  629. p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
  630. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 50));
  631. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
  632. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
  633. p.Controls.Add (c1);
  634. p.Controls.Add (c2);
  635. p.Controls.Add (c3);
  636. Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
  637. Assert.AreEqual (25, p.GetRowHeights ()[1], "D2");
  638. Assert.AreEqual (25, p.GetRowHeights ()[2], "D3");
  639. Assert.AreEqual (50, p.GetColumnWidths ()[0], "D4");
  640. Assert.AreEqual (75, p.GetColumnWidths ()[1], "D5");
  641. Assert.AreEqual (75, p.GetColumnWidths ()[2], "D6");
  642. }
  643. [Test]
  644. public void TestRowColumnSizes8 ()
  645. {
  646. // 1 Absolute and 2 Percent Columns/Rows (with total percents > 100)
  647. TableLayoutPanel p = new TableLayoutPanel ();
  648. Control c1 = new Button ();
  649. Control c2 = new Button ();
  650. Control c3 = new Button ();
  651. p.ColumnCount = 3;
  652. p.RowCount = 3;
  653. p.RowStyles.Add (new RowStyle (SizeType.Absolute, 50));
  654. p.RowStyles.Add (new RowStyle (SizeType.Percent, 100));
  655. p.RowStyles.Add (new RowStyle (SizeType.Percent, 100));
  656. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 50));
  657. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100));
  658. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100));
  659. p.Controls.Add (c1);
  660. p.Controls.Add (c2);
  661. p.Controls.Add (c3);
  662. Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
  663. Assert.AreEqual (25, p.GetRowHeights ()[1], "D2");
  664. Assert.AreEqual (25, p.GetRowHeights ()[2], "D3");
  665. Assert.AreEqual (50, p.GetColumnWidths ()[0], "D4");
  666. Assert.AreEqual (75, p.GetColumnWidths ()[1], "D5");
  667. Assert.AreEqual (75, p.GetColumnWidths ()[2], "D6");
  668. }
  669. [Test]
  670. public void TestRowColumnSizes9 ()
  671. {
  672. // 1 Absolute and 2 Percent Columns/Rows (with total percents > 100)
  673. TableLayoutPanel p = new TableLayoutPanel ();
  674. Control c1 = new Button ();
  675. Control c2 = new Button ();
  676. Control c3 = new Button ();
  677. p.ColumnCount = 3;
  678. p.RowCount = 3;
  679. p.RowStyles.Add (new RowStyle (SizeType.Absolute, 50));
  680. p.RowStyles.Add (new RowStyle (SizeType.Percent, 80));
  681. p.RowStyles.Add (new RowStyle (SizeType.Percent, 40));
  682. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 50));
  683. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 80));
  684. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 40));
  685. p.Controls.Add (c1);
  686. p.Controls.Add (c2);
  687. p.Controls.Add (c3);
  688. Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
  689. Assert.AreEqual (33, p.GetRowHeights ()[1], "D2");
  690. Assert.AreEqual (17, p.GetRowHeights ()[2], "D3");
  691. Assert.AreEqual (50, p.GetColumnWidths ()[0], "D4");
  692. Assert.AreEqual (100, p.GetColumnWidths ()[1], "D5");
  693. Assert.AreEqual (50, p.GetColumnWidths ()[2], "D6");
  694. }
  695. [Test]
  696. public void TestRowColumnSizes10 ()
  697. {
  698. // 2 AutoSize Columns/Rows
  699. TableLayoutPanel p = new TableLayoutPanel ();
  700. Control c1 = new Button ();
  701. Control c2 = new Button ();
  702. Control c3 = new Button ();
  703. p.ColumnCount = 2;
  704. p.RowCount = 2;
  705. p.RowStyles.Add (new RowStyle (SizeType.AutoSize));
  706. p.RowStyles.Add (new RowStyle (SizeType.AutoSize));
  707. p.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
  708. p.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
  709. p.Controls.Add (c1);
  710. p.Controls.Add (c2);
  711. p.Controls.Add (c3);
  712. Assert.AreEqual (29, p.GetRowHeights ()[0], "D1");
  713. Assert.AreEqual (71, p.GetRowHeights ()[1], "D2");
  714. Assert.AreEqual (81, p.GetColumnWidths ()[0], "D3");
  715. Assert.AreEqual (119, p.GetColumnWidths ()[1], "D4");
  716. }
  717. [Test]
  718. public void Bug81843 ()
  719. {
  720. Form f = new Form ();
  721. f.ShowInTaskbar = false;
  722. TableLayoutPanel tableLayoutPanel1;
  723. Button button2;
  724. TextBox textBox1;
  725. Button button4;
  726. tableLayoutPanel1 = new TableLayoutPanel ();
  727. button2 = new Button ();
  728. button4 = new Button ();
  729. textBox1 = new TextBox ();
  730. tableLayoutPanel1.SuspendLayout ();
  731. f.SuspendLayout ();
  732. tableLayoutPanel1.AutoSize = true;
  733. tableLayoutPanel1.ColumnCount = 3;
  734. tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
  735. tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
  736. tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
  737. tableLayoutPanel1.Controls.Add (button2, 0, 1);
  738. tableLayoutPanel1.Controls.Add (button4, 2, 1);
  739. tableLayoutPanel1.Controls.Add (textBox1, 1, 0);
  740. tableLayoutPanel1.Location = new Point (0, 0);
  741. tableLayoutPanel1.RowCount = 2;
  742. tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
  743. tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
  744. tableLayoutPanel1.Size = new Size (292, 287);
  745. button2.Size = new Size (75, 23);
  746. button4.Size = new Size (75, 23);
  747. textBox1.Dock = DockStyle.Fill;
  748. textBox1.Location = new Point (84, 3);
  749. textBox1.Multiline = true;
  750. textBox1.Size = new Size (94, 137);
  751. f.ClientSize = new Size (292, 312);
  752. f.Controls.Add (tableLayoutPanel1);
  753. f.Name = "Form1";
  754. f.Text = "Form1";
  755. tableLayoutPanel1.ResumeLayout (false);
  756. tableLayoutPanel1.PerformLayout ();
  757. f.ResumeLayout (false);
  758. f.PerformLayout ();
  759. f.Show ();
  760. Assert.AreEqual (new Rectangle (3, 146, 75, 23), button2.Bounds, "A1");
  761. Assert.AreEqual (new Rectangle (184, 146, 75, 23), button4.Bounds, "A2");
  762. Assert.AreEqual (new Rectangle (84, 3, 94, 137), textBox1.Bounds, "A3");
  763. f.Dispose ();
  764. }
  765. [Test] // From bug #81884
  766. public void CellBorderStyle ()
  767. {
  768. Form f = new Form ();
  769. f.ShowInTaskbar = false;
  770. TableLayoutPanel p = new TableLayoutPanel ();
  771. p = new TableLayoutPanel ();
  772. p.ColumnCount = 3;
  773. p.ColumnStyles.Add (new ColumnStyle ());
  774. p.ColumnStyles.Add (new ColumnStyle ());
  775. p.ColumnStyles.Add (new ColumnStyle ());
  776. p.Dock = DockStyle.Top;
  777. p.Height = 200;
  778. p.RowCount = 2;
  779. p.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
  780. p.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
  781. f.Controls.Add (p);
  782. Label _labelA = new Label ();
  783. _labelA.Dock = DockStyle.Fill;
  784. _labelA.Size = new Size (95, 20);
  785. _labelA.Text = "A";
  786. p.Controls.Add (_labelA, 0, 0);
  787. Label _labelB = new Label ();
  788. _labelB.Dock = DockStyle.Fill;
  789. _labelB.Size = new Size (95, 20);
  790. _labelB.Text = "B";
  791. p.Controls.Add (_labelB, 1, 0);
  792. Label _labelC = new Label ();
  793. _labelC.Dock = DockStyle.Fill;
  794. _labelC.Size = new Size (95, 20);
  795. _labelC.Text = "C";
  796. p.Controls.Add (_labelC, 2, 0);
  797. Label _labelD = new Label ();
  798. _labelD.Dock = DockStyle.Fill;
  799. _labelD.Size = new Size (95, 20);
  800. _labelD.Text = "D";
  801. p.Controls.Add (_labelD, 0, 1);
  802. Label _labelE = new Label ();
  803. _labelE.Dock = DockStyle.Fill;
  804. _labelE.Size = new Size (95, 20);
  805. _labelE.Text = "E";
  806. p.Controls.Add (_labelE, 1, 1);
  807. Label _labelF = new Label ();
  808. _labelF.Dock = DockStyle.Fill;
  809. _labelF.Size = new Size (95, 20);
  810. _labelF.Text = "F";
  811. p.Controls.Add (_labelF, 2, 1);
  812. _labelA.BackColor = Color.Red;
  813. _labelB.BackColor = Color.Orange;
  814. _labelC.BackColor = Color.Yellow;
  815. _labelD.BackColor = Color.Green;
  816. _labelE.BackColor = Color.Blue;
  817. _labelF.BackColor = Color.Purple;
  818. f.Show ();
  819. // None
  820. Assert.AreEqual (new Rectangle (3, 0, 95, 100), _labelA.Bounds, "A1");
  821. Assert.AreEqual (new Rectangle (104, 0, 95, 100), _labelB.Bounds, "A2");
  822. Assert.AreEqual (new Rectangle (205, 0, 95, 100), _labelC.Bounds, "A3");
  823. Assert.AreEqual (new Rectangle (3, 100, 95, 100), _labelD.Bounds, "A4");
  824. Assert.AreEqual (new Rectangle (104, 100, 95, 100), _labelE.Bounds, "A5");
  825. Assert.AreEqual (new Rectangle (205, 100, 95, 100), _labelF.Bounds, "A6");
  826. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
  827. Assert.AreEqual (new Rectangle (4, 1, 95, 98), _labelA.Bounds, "A7");
  828. Assert.AreEqual (new Rectangle (106, 1, 95, 98), _labelB.Bounds, "A8");
  829. Assert.AreEqual (new Rectangle (208, 1, 95, 98), _labelC.Bounds, "A9");
  830. Assert.AreEqual (new Rectangle (4, 100, 95, 99), _labelD.Bounds, "A10");
  831. Assert.AreEqual (new Rectangle (106, 100, 95, 99), _labelE.Bounds, "A11");
  832. Assert.AreEqual (new Rectangle (208, 100, 95, 99), _labelF.Bounds, "A12");
  833. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
  834. Assert.AreEqual (new Rectangle (5, 2, 95, 97), _labelA.Bounds, "A13");
  835. Assert.AreEqual (new Rectangle (108, 2, 95, 97), _labelB.Bounds, "A14");
  836. Assert.AreEqual (new Rectangle (211, 2, 95, 97), _labelC.Bounds, "A15");
  837. Assert.AreEqual (new Rectangle (5, 101, 95, 97), _labelD.Bounds, "A16");
  838. Assert.AreEqual (new Rectangle (108, 101, 95, 97), _labelE.Bounds, "A17");
  839. Assert.AreEqual (new Rectangle (211, 101, 95, 97), _labelF.Bounds, "A18");
  840. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.InsetDouble;
  841. Assert.AreEqual (new Rectangle (6, 3, 95, 95), _labelA.Bounds, "A19");
  842. Assert.AreEqual (new Rectangle (110, 3, 95, 95), _labelB.Bounds, "A20");
  843. Assert.AreEqual (new Rectangle (214, 3, 95, 95), _labelC.Bounds, "A21");
  844. Assert.AreEqual (new Rectangle (6, 101, 95, 96), _labelD.Bounds, "A22");
  845. Assert.AreEqual (new Rectangle (110, 101, 95, 96), _labelE.Bounds, "A23");
  846. Assert.AreEqual (new Rectangle (214, 101, 95, 96), _labelF.Bounds, "A24");
  847. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.Outset;
  848. Assert.AreEqual (new Rectangle (5, 2, 95, 97), _labelA.Bounds, "A25");
  849. Assert.AreEqual (new Rectangle (108, 2, 95, 97), _labelB.Bounds, "A26");
  850. Assert.AreEqual (new Rectangle (211, 2, 95, 97), _labelC.Bounds, "A27");
  851. Assert.AreEqual (new Rectangle (5, 101, 95, 97), _labelD.Bounds, "A28");
  852. Assert.AreEqual (new Rectangle (108, 101, 95, 97), _labelE.Bounds, "A29");
  853. Assert.AreEqual (new Rectangle (211, 101, 95, 97), _labelF.Bounds, "A30");
  854. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;
  855. Assert.AreEqual (new Rectangle (6, 3, 95, 95), _labelA.Bounds, "A31");
  856. Assert.AreEqual (new Rectangle (110, 3, 95, 95), _labelB.Bounds, "A32");
  857. Assert.AreEqual (new Rectangle (214, 3, 95, 95), _labelC.Bounds, "A33");
  858. Assert.AreEqual (new Rectangle (6, 101, 95, 96), _labelD.Bounds, "A34");
  859. Assert.AreEqual (new Rectangle (110, 101, 95, 96), _labelE.Bounds, "A35");
  860. Assert.AreEqual (new Rectangle (214, 101, 95, 96), _labelF.Bounds, "A36");
  861. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetPartial;
  862. Assert.AreEqual (new Rectangle (6, 3, 95, 95), _labelA.Bounds, "A37");
  863. Assert.AreEqual (new Rectangle (110, 3, 95, 95), _labelB.Bounds, "A38");
  864. Assert.AreEqual (new Rectangle (214, 3, 95, 95), _labelC.Bounds, "A39");
  865. Assert.AreEqual (new Rectangle (6, 101, 95, 96), _labelD.Bounds, "A40");
  866. Assert.AreEqual (new Rectangle (110, 101, 95, 96), _labelE.Bounds, "A41");
  867. Assert.AreEqual (new Rectangle (214, 101, 95, 96), _labelF.Bounds, "A42");
  868. f.Close ();
  869. }
  870. [Test]
  871. public void Bug81936 ()
  872. {
  873. Form f = new Form ();
  874. f.ShowInTaskbar = false;
  875. TableLayoutPanel tableLayoutPanel1;
  876. Label button2;
  877. Label button4;
  878. tableLayoutPanel1 = new TableLayoutPanel ();
  879. button2 = new Label ();
  880. button4 = new Label ();
  881. button2.Text = "Test1";
  882. button4.Text = "Test2";
  883. button2.Anchor = AnchorStyles.Left;
  884. button4.Anchor = AnchorStyles.Left;
  885. button2.Height = 14;
  886. button4.Height = 14;
  887. tableLayoutPanel1.SuspendLayout ();
  888. f.SuspendLayout ();
  889. tableLayoutPanel1.ColumnCount = 1;
  890. tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
  891. tableLayoutPanel1.Controls.Add (button2, 0, 0);
  892. tableLayoutPanel1.Controls.Add (button4, 0, 1);
  893. tableLayoutPanel1.Location = new Point (0, 0);
  894. tableLayoutPanel1.RowCount = 2;
  895. tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Absolute, 28F));
  896. tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Absolute, 28F));
  897. tableLayoutPanel1.Size = new Size (292, 56);
  898. f.ClientSize = new Size (292, 312);
  899. f.Controls.Add (tableLayoutPanel1);
  900. f.Name = "Form1";
  901. f.Text = "Form1";
  902. tableLayoutPanel1.ResumeLayout (false);
  903. tableLayoutPanel1.PerformLayout ();
  904. f.ResumeLayout (false);
  905. f.PerformLayout ();
  906. f.Show ();
  907. Assert.AreEqual (new Rectangle (3, 7, 100, 14), button2.Bounds, "A1");
  908. Assert.AreEqual (new Rectangle (3, 35, 100, 14), button4.Bounds, "A2");
  909. f.Dispose ();
  910. }
  911. [Test]
  912. public void Bug82605 ()
  913. {
  914. Form f = new Form ();
  915. f.ShowInTaskbar = false;
  916. Label l = new Label ();
  917. TableLayoutPanel table = new TableLayoutPanel ();
  918. table.ColumnCount = 1;
  919. table.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100F));
  920. table.RowCount = 2;
  921. table.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
  922. table.RowStyles.Add (new RowStyle (SizeType.Absolute, 20F));
  923. table.Controls.Add (l, 0, 1);
  924. table.Location = new Point (0, 0);
  925. table.Width = 250;
  926. l.Anchor = AnchorStyles.Left | AnchorStyles.Right;
  927. l.AutoSize = true;
  928. l.Location = new Point (3, 352);
  929. l.Size = new Size (578, 13);
  930. l.Text = "label1";
  931. l.TextAlign = ContentAlignment.MiddleCenter;
  932. f.Controls.Add (table);
  933. f.Show ();
  934. // Height is font dependent, but this bug is about the width anyways
  935. Assert.AreEqual (244, l.Width, "A1");
  936. }
  937. [Test] // bug #82040
  938. public void ShowNoChildren ()
  939. {
  940. Form form = new Form ();
  941. form.ShowInTaskbar = false;
  942. TableLayoutPanel tableLayoutPanel = new TableLayoutPanel ();
  943. tableLayoutPanel.ColumnCount = 3;
  944. tableLayoutPanel.Dock = DockStyle.Fill;
  945. tableLayoutPanel.RowCount = 11;
  946. form.Controls.Add (tableLayoutPanel);
  947. form.Show ();
  948. form.Refresh ();
  949. form.Dispose ();
  950. }
  951. [Test] // bug #82041
  952. public void DontCallResumeLayout ()
  953. {
  954. Form form = new Form ();
  955. form.ShowInTaskbar = false;
  956. TableLayoutPanel tableLayoutPanel = new TableLayoutPanel ();
  957. form.Controls.Add (tableLayoutPanel);
  958. tableLayoutPanel.SuspendLayout ();
  959. tableLayoutPanel.ColumnCount = 3;
  960. tableLayoutPanel.Dock = DockStyle.Fill;
  961. tableLayoutPanel.RowCount = 11;
  962. tableLayoutPanel.Controls.Add (new Button ());
  963. form.Show ();
  964. form.Refresh ();
  965. form.Dispose ();
  966. }
  967. [Test] // bug #346246
  968. public void AutoSizePanelVerical ()
  969. {
  970. Form f = new Form ();
  971. f.ShowInTaskbar = false;
  972. TableLayoutPanel tlp = new TableLayoutPanel ();
  973. tlp.AutoSize = true;
  974. tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
  975. tlp.ColumnCount = 1;
  976. tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100F));
  977. tlp.Location = new Point (12, 12);
  978. tlp.Name = "tableLayoutPanel1";
  979. tlp.RowCount = 2;
  980. tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
  981. tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
  982. tlp.Size = new Size (139, 182);
  983. tlp.TabIndex = 0;
  984. f.Controls.Add (tlp);
  985. Button b = new Button ();
  986. b.Size = new Size (100, 100);
  987. tlp.Controls.Add (b, 0, 0);
  988. PictureBox p = new PictureBox ();
  989. p.Size = new Size (100, 100);
  990. tlp.Controls.Add (p,0,1);
  991. f.Show ();
  992. Assert.AreEqual (new Rectangle (12, 12, 106, 212), tlp.Bounds, "A1");
  993. Assert.AreEqual (new Rectangle (3, 3, 100, 100), b.Bounds, "A2");
  994. Assert.AreEqual (new Rectangle (3, 109, 100, 100), p.Bounds, "A3");
  995. b.Width += 20;
  996. b.Height += 20;
  997. Assert.AreEqual (new Rectangle (12, 12, 126, 252), tlp.Bounds, "B1");
  998. Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "B2");
  999. Assert.AreEqual (new Rectangle (3, 129, 100, 100), p.Bounds, "B3");
  1000. p.Width += 20;
  1001. p.Height += 20;
  1002. Assert.AreEqual (new Rectangle (12, 12, 126, 252), tlp.Bounds, "C1");
  1003. Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "C2");
  1004. Assert.AreEqual (new Rectangle (3, 129, 120, 120), p.Bounds, "C3");
  1005. f.Dispose ();
  1006. }
  1007. [Test] // bug #346246
  1008. public void AutoSizePanelHorizontal ()
  1009. {
  1010. Form f = new Form ();
  1011. f.ShowInTaskbar = false;
  1012. TableLayoutPanel tlp = new TableLayoutPanel ();
  1013. tlp.AutoSize = true;
  1014. tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
  1015. tlp.ColumnCount = 2;
  1016. tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50F));
  1017. tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50F));
  1018. tlp.Location = new Point (12, 12);
  1019. tlp.Name = "tableLayoutPanel1";
  1020. tlp.RowCount = 1;
  1021. tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
  1022. tlp.Size = new Size (139, 182);
  1023. tlp.TabIndex = 0;
  1024. f.Controls.Add (tlp);
  1025. Button b = new Button ();
  1026. b.Size = new Size (100, 100);
  1027. tlp.Controls.Add (b, 0, 0);
  1028. PictureBox p = new PictureBox ();
  1029. p.Size = new Size (100, 100);
  1030. tlp.Controls.Add (p, 1, 0);
  1031. f.Show ();
  1032. Assert.AreEqual (new Rectangle (12, 12, 212, 106), tlp.Bounds, "A1");
  1033. Assert.AreEqual (new Rectangle (3, 3, 100, 100), b.Bounds, "A2");
  1034. Assert.AreEqual (new Rectangle (109, 3, 100, 100), p.Bounds, "A3");
  1035. b.Width += 20;
  1036. b.Height += 20;
  1037. Assert.AreEqual (new Rectangle (12, 12, 252, 126), tlp.Bounds, "B1");
  1038. Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "B2");
  1039. Assert.AreEqual (new Rectangle (129, 3, 100, 100), p.Bounds, "B3");
  1040. p.Width += 20;
  1041. p.Height += 20;
  1042. Assert.AreEqual (new Rectangle (12, 12, 252, 126), tlp.Bounds, "C1");
  1043. Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "C2");
  1044. Assert.AreEqual (new Rectangle (129, 3, 120, 120), p.Bounds, "C3");
  1045. f.Dispose ();
  1046. }
  1047. [Test]
  1048. public void Bug354676 ()
  1049. {
  1050. Form f = new Form ();
  1051. TableLayoutPanel tlp = new TableLayoutPanel ();
  1052. tlp.Dock = DockStyle.Fill;
  1053. tlp.Padding = new Padding (40);
  1054. tlp.RowCount = 2;
  1055. tlp.ColumnCount = 1;
  1056. f.Controls.Add (tlp);
  1057. Button b1 = new Button ();
  1058. tlp.Controls.Add (b1);
  1059. Button b2 = new Button ();
  1060. tlp.Controls.Add (b2);
  1061. f.Show ();
  1062. Assert.AreEqual (new Rectangle (43, 43, 75, 23), b1.Bounds, "A1");
  1063. Assert.AreEqual (new Rectangle (43, 72, 75, 23), b2.Bounds, "A2");
  1064. f.Close ();
  1065. f.Dispose ();
  1066. }
  1067. [Test]
  1068. public void Bug355408 ()
  1069. {
  1070. Form f = new Form ();
  1071. f.ClientSize = new Size (300, 300);
  1072. TableLayoutPanel tlp = new TableLayoutPanel ();
  1073. tlp.Dock = DockStyle.Fill;
  1074. tlp.RowCount = 2;
  1075. tlp.ColumnCount = 2;
  1076. f.Controls.Add (tlp);
  1077. Button b1 = new Button ();
  1078. tlp.Controls.Add (b1);
  1079. Button b2 = new Button ();
  1080. tlp.Controls.Add (b2);
  1081. Button b3 = new Button ();
  1082. b3.Dock = DockStyle.Fill;
  1083. b3.Width = 250;
  1084. tlp.SetColumnSpan (b3, 2);
  1085. tlp.Controls.Add (b3);
  1086. f.Show ();
  1087. Assert.AreEqual (new Rectangle (3, 3, 75, 23), b1.Bounds, "A1");
  1088. Assert.AreEqual (new Rectangle (84, 3, 75, 23), b2.Bounds, "A2");
  1089. Assert.AreEqual (new Rectangle (3, 32, 294, 265), b3.Bounds, "A3");
  1090. f.Close ();
  1091. f.Dispose ();
  1092. }
  1093. [Test]
  1094. public void Bug402651 ()
  1095. {
  1096. Form f = new Form ();
  1097. f.ClientSize = new Size (300, 300);
  1098. TableLayoutPanel tlp = new TableLayoutPanel ();
  1099. tlp.Dock = DockStyle.Fill;
  1100. tlp.RowCount = 2;
  1101. tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
  1102. tlp.RowStyles.Add (new RowStyle (SizeType.AutoSize));
  1103. f.Controls.Add (tlp);
  1104. Button b1 = new Button ();
  1105. b1.Text = String.Empty;
  1106. b1.Dock = DockStyle.Fill;
  1107. tlp.Controls.Add (b1, 0, 0);
  1108. Button b2 = new Button ();
  1109. b2.Text = String.Empty;
  1110. b2.Size = new Size (100, 100);
  1111. b2.Anchor = AnchorStyles.None;
  1112. b2.Dock = DockStyle.None;
  1113. b2.Visible = false;
  1114. tlp.Controls.Add (b2, 0, 1);
  1115. f.Show ();
  1116. b2.Visible = true;
  1117. Assert.AreEqual (new Size (100, 100), b2.Size, "A1");
  1118. b2.Visible = false;
  1119. b2.Anchor = AnchorStyles.Left;
  1120. b2.Visible = true;
  1121. Assert.AreEqual (new Size (100, 100), b2.Size, "A2");
  1122. f.Dispose ();
  1123. }
  1124. [Test]
  1125. public void Bug354672 ()
  1126. {
  1127. Form f = new Form ();
  1128. f.ClientSize = new Size (300, 300);
  1129. TableLayoutPanel tlp = new TableLayoutPanel ();
  1130. tlp.AutoSize = true;
  1131. tlp.ColumnCount = 2;
  1132. tlp.RowCount = 1;
  1133. f.Controls.Add (tlp);
  1134. TextBox t1 = new TextBox ();
  1135. t1.Dock = DockStyle.Fill;
  1136. tlp.Controls.Add (t1);
  1137. TextBox t2 = new TextBox ();
  1138. t2.Dock = DockStyle.Fill;
  1139. tlp.Controls.Add (t2);
  1140. Assert.AreEqual (new Size (212, t1.Height + 6), tlp.PreferredSize, "A1");
  1141. f.Dispose ();
  1142. }
  1143. [Test]
  1144. public void Bug354672More ()
  1145. {
  1146. Form f = new Form ();
  1147. f.ClientSize = new Size (300, 300);
  1148. TableLayoutPanel tlp = new TableLayoutPanel ();
  1149. tlp.AutoSize = true;
  1150. tlp.ColumnCount = 2;
  1151. tlp.RowCount = 1;
  1152. tlp.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
  1153. tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50f));
  1154. f.Controls.Add (tlp);
  1155. TextBox t1 = new TextBox ();
  1156. t1.Dock = DockStyle.Fill;
  1157. tlp.Controls.Add (t1);
  1158. TextBox t2 = new TextBox ();
  1159. t2.Dock = DockStyle.Fill;
  1160. tlp.Controls.Add (t2);
  1161. Assert.AreEqual (new Size (212, t1.Height + 6), tlp.PreferredSize, "A1");
  1162. f.Dispose ();
  1163. }
  1164. [Test]
  1165. public void Bug367249 ()
  1166. {
  1167. // Setting a colspan greater than the number of columns was
  1168. // causing an IOORE, this test just should not exception
  1169. TableLayoutPanel LayoutPanel = new TableLayoutPanel ();
  1170. LayoutPanel.ColumnCount = 1;
  1171. LayoutPanel.RowCount = 2;
  1172. Button OkButton = new Button ();
  1173. OkButton.Text = "OK";
  1174. LayoutPanel.Controls.Add (OkButton);
  1175. LayoutPanel.SetColumnSpan (OkButton, 3);
  1176. }
  1177. [Test]
  1178. public void Bug396141 ()
  1179. {
  1180. // The issue is the user has set the RowCount to 0, but after
  1181. // we arrange the controls, we have 1 row. GetPreferredSize (for
  1182. // AutoSize) was using 0 instead of 1.
  1183. Form f = new Form ();
  1184. f.ClientSize = new Size (300, 300);
  1185. f.ShowInTaskbar = false;
  1186. TableLayoutPanel tlp = new TableLayoutPanel ();
  1187. tlp.AutoSize = true;
  1188. tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
  1189. tlp.ColumnCount = 2;
  1190. tlp.RowCount = 0;
  1191. f.Controls.Add (tlp);
  1192. TextBox t1 = new TextBox ();
  1193. t1.Dock = DockStyle.Fill;
  1194. tlp.Controls.Add (t1);
  1195. TextBox t2 = new TextBox ();
  1196. t2.Dock = DockStyle.Fill;
  1197. tlp.Controls.Add (t2);
  1198. f.Show ();
  1199. Assert.IsTrue (tlp.Height > 0, "Height must be > 0");
  1200. Assert.IsTrue (tlp.Width > 0, "Width must be > 0");
  1201. f.Dispose ();
  1202. }
  1203. [Test]
  1204. public void Bug396433 ()
  1205. {
  1206. // We were not taking the CellBorderStyle into account when calculating
  1207. // the preferred size.
  1208. Form f = new Form ();
  1209. f.ClientSize = new Size (300, 300);
  1210. f.ShowInTaskbar = false;
  1211. TableLayoutPanel tlp = new TableLayoutPanel ();
  1212. tlp.AutoSize = true;
  1213. tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
  1214. tlp.ColumnCount = 2;
  1215. tlp.RowCount = 1;
  1216. f.Controls.Add (tlp);
  1217. Button t1 = new Button ();
  1218. tlp.Controls.Add (t1);
  1219. Button t2 = new Button ();
  1220. tlp.Controls.Add (t2);
  1221. f.Show ();
  1222. Assert.AreEqual (new Size (162, 29), tlp.PreferredSize, "A1");
  1223. tlp.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
  1224. Assert.AreEqual (new Size (165, 31), tlp.PreferredSize, "A2");
  1225. f.Dispose ();
  1226. }
  1227. [Test]
  1228. public void IgnoreAutoSizeMode ()
  1229. {
  1230. // It would seem that AutoSizeMode for a TableLayoutPanel is always
  1231. // treated as GrowAndShrink
  1232. Form f = new Form ();
  1233. f.ClientSize = new Size (300, 300);
  1234. f.ShowInTaskbar = false;
  1235. TableLayoutPanel tlp = new TableLayoutPanel ();
  1236. tlp.AutoSize = true;
  1237. tlp.Dock = DockStyle.Top;
  1238. tlp.ColumnCount = 1;
  1239. tlp.RowCount = 1;
  1240. f.Controls.Add (tlp);
  1241. Button t1 = new Button ();
  1242. tlp.Controls.Add (t1);
  1243. f.Show ();
  1244. Assert.AreEqual (29, tlp.Height, "A1");
  1245. tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
  1246. Assert.AreEqual (29, tlp.Height, "A2");
  1247. f.Dispose ();
  1248. }
  1249. [Test]
  1250. public void TestTableLayoutStyleOwned ()
  1251. {
  1252. try {
  1253. ColumnStyle style = new ColumnStyle ();
  1254. TableLayoutColumnStyleCollection coll = new TableLayoutPanel ().ColumnStyles;
  1255. coll.Add (style);
  1256. TableLayoutColumnStyleCollection coll2 = new TableLayoutPanel ().ColumnStyles;
  1257. coll2.Add (style);
  1258. Assert.Fail ("#1");
  1259. } catch (ArgumentException ex) {
  1260. // PASS
  1261. }
  1262. try {
  1263. RowStyle style = new RowStyle ();
  1264. TableLayoutRowStyleCollection coll = new TableLayoutPanel ().RowStyles;
  1265. coll.Add (style);
  1266. TableLayoutRowStyleCollection coll2 = new TableLayoutPanel ().RowStyles;
  1267. coll2.Add (style);
  1268. Assert.Fail ("#2");
  1269. } catch (ArgumentException ex) {
  1270. // PASS
  1271. }
  1272. }
  1273. }
  1274. }
  1275. #endif