TableLayoutTest.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  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
  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 TestRowColumnSizes1 ()
  477. {
  478. // Row span = 2, but control is in the last row, creates new row
  479. TableLayoutPanel p = new TableLayoutPanel ();
  480. Control c1 = new Button ();
  481. Control c2 = new Button ();
  482. Control c3 = new Button ();
  483. p.ColumnCount = 2;
  484. p.RowCount = 1;
  485. p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
  486. p.Controls.Add (c1);
  487. p.Controls.Add (c2);
  488. p.Controls.Add (c3);
  489. Assert.AreEqual (71, p.GetRowHeights ()[0], "D1");
  490. Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
  491. }
  492. [Test]
  493. public void TestRowColumnSizes2 ()
  494. {
  495. // Row span = 2, but control is in the last row, creates new row
  496. TableLayoutPanel p = new TableLayoutPanel ();
  497. Control c1 = new Button ();
  498. Control c2 = new Button ();
  499. Control c3 = new Button ();
  500. p.ColumnCount = 2;
  501. p.RowCount = 1;
  502. p.RowStyles.Add (new RowStyle (SizeType.Absolute, 100F));
  503. p.Controls.Add (c1);
  504. p.Controls.Add (c2);
  505. p.Controls.Add (c3);
  506. Assert.AreEqual (100, p.GetRowHeights ()[0], "D1");
  507. Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
  508. }
  509. [Test]
  510. public void TestRowColumnSizes3 ()
  511. {
  512. // Row span = 2, but control is in the last row, creates new row
  513. TableLayoutPanel p = new TableLayoutPanel ();
  514. Control c1 = new Button ();
  515. Control c2 = new Button ();
  516. Control c3 = new Button ();
  517. Control c4 = new Button ();
  518. Control c5 = new Button ();
  519. p.ColumnCount = 2;
  520. p.RowCount = 1;
  521. p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
  522. p.Controls.Add (c1);
  523. p.Controls.Add (c2);
  524. p.Controls.Add (c3);
  525. p.Controls.Add (c4);
  526. p.Controls.Add (c5);
  527. Assert.AreEqual (42, p.GetRowHeights ()[0], "D1");
  528. Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
  529. Assert.AreEqual (29, p.GetRowHeights ()[2], "D3");
  530. }
  531. [Test]
  532. public void TestRowColumnSizes4 ()
  533. {
  534. // Row span = 2, but control is in the last row, creates new row
  535. TableLayoutPanel p = new TableLayoutPanel ();
  536. Control c1 = new Button ();
  537. Control c2 = new Button ();
  538. Control c3 = new Button ();
  539. Control c4 = new Button ();
  540. Control c5 = new Button ();
  541. Control c6 = new Button ();
  542. Control c7 = new Button ();
  543. p.ColumnCount = 2;
  544. p.RowCount = 1;
  545. p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
  546. p.Controls.Add (c1);
  547. p.Controls.Add (c2);
  548. p.Controls.Add (c3);
  549. p.Controls.Add (c4);
  550. p.Controls.Add (c5);
  551. p.Controls.Add (c6);
  552. p.Controls.Add (c7);
  553. //Assert.AreEqual (100, p.GetRowHeights ()[0], "D1");
  554. Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
  555. Assert.AreEqual (29, p.GetRowHeights ()[2], "D3");
  556. Assert.AreEqual (29, p.GetRowHeights ()[3], "D4");
  557. }
  558. [Test]
  559. public void TestRowColumnSizes5 ()
  560. {
  561. // 2 Absolute Columns/Rows
  562. TableLayoutPanel p = new TableLayoutPanel ();
  563. Control c1 = new Button ();
  564. Control c2 = new Button ();
  565. Control c3 = new Button ();
  566. p.ColumnCount = 2;
  567. p.RowCount = 2;
  568. p.RowStyles.Add (new RowStyle (SizeType.Absolute, 20));
  569. p.RowStyles.Add (new RowStyle (SizeType.Absolute, 30));
  570. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20));
  571. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 30));
  572. p.Controls.Add (c1);
  573. p.Controls.Add (c2);
  574. p.Controls.Add (c3);
  575. Assert.AreEqual (20, p.GetRowHeights ()[0], "D1");
  576. Assert.AreEqual (80, p.GetRowHeights ()[1], "D2");
  577. Assert.AreEqual (20, p.GetColumnWidths ()[0], "D3");
  578. Assert.AreEqual (180, p.GetColumnWidths ()[1], "D4");
  579. }
  580. [Test]
  581. public void TestRowColumnSizes6 ()
  582. {
  583. // 2 50% Columns/Rows
  584. TableLayoutPanel p = new TableLayoutPanel ();
  585. Control c1 = new Button ();
  586. Control c2 = new Button ();
  587. Control c3 = new Button ();
  588. p.ColumnCount = 2;
  589. p.RowCount = 2;
  590. p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
  591. p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
  592. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
  593. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
  594. p.Controls.Add (c1);
  595. p.Controls.Add (c2);
  596. p.Controls.Add (c3);
  597. Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
  598. Assert.AreEqual (50, p.GetRowHeights ()[1], "D2");
  599. Assert.AreEqual (100, p.GetColumnWidths ()[0], "D3");
  600. Assert.AreEqual (100, p.GetColumnWidths ()[1], "D4");
  601. }
  602. [Test]
  603. public void TestRowColumnSizes7 ()
  604. {
  605. // 1 Absolute and 2 Percent Columns/Rows
  606. TableLayoutPanel p = new TableLayoutPanel ();
  607. Control c1 = new Button ();
  608. Control c2 = new Button ();
  609. Control c3 = new Button ();
  610. p.ColumnCount = 3;
  611. p.RowCount = 3;
  612. p.RowStyles.Add (new RowStyle (SizeType.Absolute, 50));
  613. p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
  614. p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
  615. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 50));
  616. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
  617. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
  618. p.Controls.Add (c1);
  619. p.Controls.Add (c2);
  620. p.Controls.Add (c3);
  621. Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
  622. Assert.AreEqual (25, p.GetRowHeights ()[1], "D2");
  623. Assert.AreEqual (25, p.GetRowHeights ()[2], "D3");
  624. Assert.AreEqual (50, p.GetColumnWidths ()[0], "D4");
  625. Assert.AreEqual (75, p.GetColumnWidths ()[1], "D5");
  626. Assert.AreEqual (75, p.GetColumnWidths ()[2], "D6");
  627. }
  628. [Test]
  629. public void TestRowColumnSizes8 ()
  630. {
  631. // 1 Absolute and 2 Percent Columns/Rows (with total percents > 100)
  632. TableLayoutPanel p = new TableLayoutPanel ();
  633. Control c1 = new Button ();
  634. Control c2 = new Button ();
  635. Control c3 = new Button ();
  636. p.ColumnCount = 3;
  637. p.RowCount = 3;
  638. p.RowStyles.Add (new RowStyle (SizeType.Absolute, 50));
  639. p.RowStyles.Add (new RowStyle (SizeType.Percent, 100));
  640. p.RowStyles.Add (new RowStyle (SizeType.Percent, 100));
  641. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 50));
  642. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100));
  643. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100));
  644. p.Controls.Add (c1);
  645. p.Controls.Add (c2);
  646. p.Controls.Add (c3);
  647. Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
  648. Assert.AreEqual (25, p.GetRowHeights ()[1], "D2");
  649. Assert.AreEqual (25, p.GetRowHeights ()[2], "D3");
  650. Assert.AreEqual (50, p.GetColumnWidths ()[0], "D4");
  651. Assert.AreEqual (75, p.GetColumnWidths ()[1], "D5");
  652. Assert.AreEqual (75, p.GetColumnWidths ()[2], "D6");
  653. }
  654. [Test]
  655. public void TestRowColumnSizes9 ()
  656. {
  657. // 1 Absolute and 2 Percent Columns/Rows (with total percents > 100)
  658. TableLayoutPanel p = new TableLayoutPanel ();
  659. Control c1 = new Button ();
  660. Control c2 = new Button ();
  661. Control c3 = new Button ();
  662. p.ColumnCount = 3;
  663. p.RowCount = 3;
  664. p.RowStyles.Add (new RowStyle (SizeType.Absolute, 50));
  665. p.RowStyles.Add (new RowStyle (SizeType.Percent, 80));
  666. p.RowStyles.Add (new RowStyle (SizeType.Percent, 40));
  667. p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 50));
  668. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 80));
  669. p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 40));
  670. p.Controls.Add (c1);
  671. p.Controls.Add (c2);
  672. p.Controls.Add (c3);
  673. Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
  674. Assert.AreEqual (33, p.GetRowHeights ()[1], "D2");
  675. Assert.AreEqual (17, p.GetRowHeights ()[2], "D3");
  676. Assert.AreEqual (50, p.GetColumnWidths ()[0], "D4");
  677. Assert.AreEqual (100, p.GetColumnWidths ()[1], "D5");
  678. Assert.AreEqual (50, p.GetColumnWidths ()[2], "D6");
  679. }
  680. [Test]
  681. public void TestRowColumnSizes10 ()
  682. {
  683. // 2 AutoSize Columns/Rows
  684. TableLayoutPanel p = new TableLayoutPanel ();
  685. Control c1 = new Button ();
  686. Control c2 = new Button ();
  687. Control c3 = new Button ();
  688. p.ColumnCount = 2;
  689. p.RowCount = 2;
  690. p.RowStyles.Add (new RowStyle (SizeType.AutoSize));
  691. p.RowStyles.Add (new RowStyle (SizeType.AutoSize));
  692. p.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
  693. p.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
  694. p.Controls.Add (c1);
  695. p.Controls.Add (c2);
  696. p.Controls.Add (c3);
  697. Assert.AreEqual (29, p.GetRowHeights ()[0], "D1");
  698. Assert.AreEqual (71, p.GetRowHeights ()[1], "D2");
  699. Assert.AreEqual (81, p.GetColumnWidths ()[0], "D3");
  700. Assert.AreEqual (119, p.GetColumnWidths ()[1], "D4");
  701. }
  702. }
  703. }
  704. #endif