TableLayoutTest.cs 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382
  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. [Test]
  703. public void Bug81843 ()
  704. {
  705. Form f = new Form ();
  706. f.ShowInTaskbar = false;
  707. TableLayoutPanel tableLayoutPanel1;
  708. Button button2;
  709. TextBox textBox1;
  710. Button button4;
  711. tableLayoutPanel1 = new TableLayoutPanel ();
  712. button2 = new Button ();
  713. button4 = new Button ();
  714. textBox1 = new TextBox ();
  715. tableLayoutPanel1.SuspendLayout ();
  716. f.SuspendLayout ();
  717. tableLayoutPanel1.AutoSize = true;
  718. tableLayoutPanel1.ColumnCount = 3;
  719. tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
  720. tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
  721. tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
  722. tableLayoutPanel1.Controls.Add (button2, 0, 1);
  723. tableLayoutPanel1.Controls.Add (button4, 2, 1);
  724. tableLayoutPanel1.Controls.Add (textBox1, 1, 0);
  725. tableLayoutPanel1.Location = new Point (0, 0);
  726. tableLayoutPanel1.RowCount = 2;
  727. tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
  728. tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
  729. tableLayoutPanel1.Size = new Size (292, 287);
  730. button2.Size = new Size (75, 23);
  731. button4.Size = new Size (75, 23);
  732. textBox1.Dock = DockStyle.Fill;
  733. textBox1.Location = new Point (84, 3);
  734. textBox1.Multiline = true;
  735. textBox1.Size = new Size (94, 137);
  736. f.ClientSize = new Size (292, 312);
  737. f.Controls.Add (tableLayoutPanel1);
  738. f.Name = "Form1";
  739. f.Text = "Form1";
  740. tableLayoutPanel1.ResumeLayout (false);
  741. tableLayoutPanel1.PerformLayout ();
  742. f.ResumeLayout (false);
  743. f.PerformLayout ();
  744. f.Show ();
  745. Assert.AreEqual (new Rectangle (3, 146, 75, 23), button2.Bounds, "A1");
  746. Assert.AreEqual (new Rectangle (184, 146, 75, 23), button4.Bounds, "A2");
  747. Assert.AreEqual (new Rectangle (84, 3, 94, 137), textBox1.Bounds, "A3");
  748. f.Dispose ();
  749. }
  750. [Test] // From bug #81884
  751. public void CellBorderStyle ()
  752. {
  753. Form f = new Form ();
  754. f.ShowInTaskbar = false;
  755. TableLayoutPanel p = new TableLayoutPanel ();
  756. p = new TableLayoutPanel ();
  757. p.ColumnCount = 3;
  758. p.ColumnStyles.Add (new ColumnStyle ());
  759. p.ColumnStyles.Add (new ColumnStyle ());
  760. p.ColumnStyles.Add (new ColumnStyle ());
  761. p.Dock = DockStyle.Top;
  762. p.Height = 200;
  763. p.RowCount = 2;
  764. p.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
  765. p.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
  766. f.Controls.Add (p);
  767. Label _labelA = new Label ();
  768. _labelA.Dock = DockStyle.Fill;
  769. _labelA.Size = new Size (95, 20);
  770. _labelA.Text = "A";
  771. p.Controls.Add (_labelA, 0, 0);
  772. Label _labelB = new Label ();
  773. _labelB.Dock = DockStyle.Fill;
  774. _labelB.Size = new Size (95, 20);
  775. _labelB.Text = "B";
  776. p.Controls.Add (_labelB, 1, 0);
  777. Label _labelC = new Label ();
  778. _labelC.Dock = DockStyle.Fill;
  779. _labelC.Size = new Size (95, 20);
  780. _labelC.Text = "C";
  781. p.Controls.Add (_labelC, 2, 0);
  782. Label _labelD = new Label ();
  783. _labelD.Dock = DockStyle.Fill;
  784. _labelD.Size = new Size (95, 20);
  785. _labelD.Text = "D";
  786. p.Controls.Add (_labelD, 0, 1);
  787. Label _labelE = new Label ();
  788. _labelE.Dock = DockStyle.Fill;
  789. _labelE.Size = new Size (95, 20);
  790. _labelE.Text = "E";
  791. p.Controls.Add (_labelE, 1, 1);
  792. Label _labelF = new Label ();
  793. _labelF.Dock = DockStyle.Fill;
  794. _labelF.Size = new Size (95, 20);
  795. _labelF.Text = "F";
  796. p.Controls.Add (_labelF, 2, 1);
  797. _labelA.BackColor = Color.Red;
  798. _labelB.BackColor = Color.Orange;
  799. _labelC.BackColor = Color.Yellow;
  800. _labelD.BackColor = Color.Green;
  801. _labelE.BackColor = Color.Blue;
  802. _labelF.BackColor = Color.Purple;
  803. f.Show ();
  804. // None
  805. Assert.AreEqual (new Rectangle (3, 0, 95, 100), _labelA.Bounds, "A1");
  806. Assert.AreEqual (new Rectangle (104, 0, 95, 100), _labelB.Bounds, "A2");
  807. Assert.AreEqual (new Rectangle (205, 0, 95, 100), _labelC.Bounds, "A3");
  808. Assert.AreEqual (new Rectangle (3, 100, 95, 100), _labelD.Bounds, "A4");
  809. Assert.AreEqual (new Rectangle (104, 100, 95, 100), _labelE.Bounds, "A5");
  810. Assert.AreEqual (new Rectangle (205, 100, 95, 100), _labelF.Bounds, "A6");
  811. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
  812. Assert.AreEqual (new Rectangle (4, 1, 95, 98), _labelA.Bounds, "A7");
  813. Assert.AreEqual (new Rectangle (106, 1, 95, 98), _labelB.Bounds, "A8");
  814. Assert.AreEqual (new Rectangle (208, 1, 95, 98), _labelC.Bounds, "A9");
  815. Assert.AreEqual (new Rectangle (4, 100, 95, 99), _labelD.Bounds, "A10");
  816. Assert.AreEqual (new Rectangle (106, 100, 95, 99), _labelE.Bounds, "A11");
  817. Assert.AreEqual (new Rectangle (208, 100, 95, 99), _labelF.Bounds, "A12");
  818. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
  819. Assert.AreEqual (new Rectangle (5, 2, 95, 97), _labelA.Bounds, "A13");
  820. Assert.AreEqual (new Rectangle (108, 2, 95, 97), _labelB.Bounds, "A14");
  821. Assert.AreEqual (new Rectangle (211, 2, 95, 97), _labelC.Bounds, "A15");
  822. Assert.AreEqual (new Rectangle (5, 101, 95, 97), _labelD.Bounds, "A16");
  823. Assert.AreEqual (new Rectangle (108, 101, 95, 97), _labelE.Bounds, "A17");
  824. Assert.AreEqual (new Rectangle (211, 101, 95, 97), _labelF.Bounds, "A18");
  825. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.InsetDouble;
  826. Assert.AreEqual (new Rectangle (6, 3, 95, 95), _labelA.Bounds, "A19");
  827. Assert.AreEqual (new Rectangle (110, 3, 95, 95), _labelB.Bounds, "A20");
  828. Assert.AreEqual (new Rectangle (214, 3, 95, 95), _labelC.Bounds, "A21");
  829. Assert.AreEqual (new Rectangle (6, 101, 95, 96), _labelD.Bounds, "A22");
  830. Assert.AreEqual (new Rectangle (110, 101, 95, 96), _labelE.Bounds, "A23");
  831. Assert.AreEqual (new Rectangle (214, 101, 95, 96), _labelF.Bounds, "A24");
  832. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.Outset;
  833. Assert.AreEqual (new Rectangle (5, 2, 95, 97), _labelA.Bounds, "A25");
  834. Assert.AreEqual (new Rectangle (108, 2, 95, 97), _labelB.Bounds, "A26");
  835. Assert.AreEqual (new Rectangle (211, 2, 95, 97), _labelC.Bounds, "A27");
  836. Assert.AreEqual (new Rectangle (5, 101, 95, 97), _labelD.Bounds, "A28");
  837. Assert.AreEqual (new Rectangle (108, 101, 95, 97), _labelE.Bounds, "A29");
  838. Assert.AreEqual (new Rectangle (211, 101, 95, 97), _labelF.Bounds, "A30");
  839. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;
  840. Assert.AreEqual (new Rectangle (6, 3, 95, 95), _labelA.Bounds, "A31");
  841. Assert.AreEqual (new Rectangle (110, 3, 95, 95), _labelB.Bounds, "A32");
  842. Assert.AreEqual (new Rectangle (214, 3, 95, 95), _labelC.Bounds, "A33");
  843. Assert.AreEqual (new Rectangle (6, 101, 95, 96), _labelD.Bounds, "A34");
  844. Assert.AreEqual (new Rectangle (110, 101, 95, 96), _labelE.Bounds, "A35");
  845. Assert.AreEqual (new Rectangle (214, 101, 95, 96), _labelF.Bounds, "A36");
  846. p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetPartial;
  847. Assert.AreEqual (new Rectangle (6, 3, 95, 95), _labelA.Bounds, "A37");
  848. Assert.AreEqual (new Rectangle (110, 3, 95, 95), _labelB.Bounds, "A38");
  849. Assert.AreEqual (new Rectangle (214, 3, 95, 95), _labelC.Bounds, "A39");
  850. Assert.AreEqual (new Rectangle (6, 101, 95, 96), _labelD.Bounds, "A40");
  851. Assert.AreEqual (new Rectangle (110, 101, 95, 96), _labelE.Bounds, "A41");
  852. Assert.AreEqual (new Rectangle (214, 101, 95, 96), _labelF.Bounds, "A42");
  853. f.Close ();
  854. }
  855. [Test]
  856. public void Bug81936 ()
  857. {
  858. Form f = new Form ();
  859. f.ShowInTaskbar = false;
  860. TableLayoutPanel tableLayoutPanel1;
  861. Label button2;
  862. Label button4;
  863. tableLayoutPanel1 = new TableLayoutPanel ();
  864. button2 = new Label ();
  865. button4 = new Label ();
  866. button2.Text = "Test1";
  867. button4.Text = "Test2";
  868. button2.Anchor = AnchorStyles.Left;
  869. button4.Anchor = AnchorStyles.Left;
  870. button2.Height = 14;
  871. button4.Height = 14;
  872. tableLayoutPanel1.SuspendLayout ();
  873. f.SuspendLayout ();
  874. tableLayoutPanel1.ColumnCount = 1;
  875. tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
  876. tableLayoutPanel1.Controls.Add (button2, 0, 0);
  877. tableLayoutPanel1.Controls.Add (button4, 0, 1);
  878. tableLayoutPanel1.Location = new Point (0, 0);
  879. tableLayoutPanel1.RowCount = 2;
  880. tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Absolute, 28F));
  881. tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Absolute, 28F));
  882. tableLayoutPanel1.Size = new Size (292, 56);
  883. f.ClientSize = new Size (292, 312);
  884. f.Controls.Add (tableLayoutPanel1);
  885. f.Name = "Form1";
  886. f.Text = "Form1";
  887. tableLayoutPanel1.ResumeLayout (false);
  888. tableLayoutPanel1.PerformLayout ();
  889. f.ResumeLayout (false);
  890. f.PerformLayout ();
  891. f.Show ();
  892. Assert.AreEqual (new Rectangle (3, 7, 100, 14), button2.Bounds, "A1");
  893. Assert.AreEqual (new Rectangle (3, 35, 100, 14), button4.Bounds, "A2");
  894. f.Dispose ();
  895. }
  896. [Test]
  897. public void Bug82605 ()
  898. {
  899. Form f = new Form ();
  900. f.ShowInTaskbar = false;
  901. Label l = new Label ();
  902. TableLayoutPanel table = new TableLayoutPanel ();
  903. table.ColumnCount = 1;
  904. table.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100F));
  905. table.RowCount = 2;
  906. table.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
  907. table.RowStyles.Add (new RowStyle (SizeType.Absolute, 20F));
  908. table.Controls.Add (l, 0, 1);
  909. table.Location = new Point (0, 0);
  910. table.Width = 250;
  911. l.Anchor = AnchorStyles.Left | AnchorStyles.Right;
  912. l.AutoSize = true;
  913. l.Location = new Point (3, 352);
  914. l.Size = new Size (578, 13);
  915. l.Text = "label1";
  916. l.TextAlign = ContentAlignment.MiddleCenter;
  917. f.Controls.Add (table);
  918. f.Show ();
  919. // Height is font dependent, but this bug is about the width anyways
  920. Assert.AreEqual (244, l.Width, "A1");
  921. }
  922. [Test] // bug #82040
  923. public void ShowNoChildren ()
  924. {
  925. Form form = new Form ();
  926. form.ShowInTaskbar = false;
  927. TableLayoutPanel tableLayoutPanel = new TableLayoutPanel ();
  928. tableLayoutPanel.ColumnCount = 3;
  929. tableLayoutPanel.Dock = DockStyle.Fill;
  930. tableLayoutPanel.RowCount = 11;
  931. form.Controls.Add (tableLayoutPanel);
  932. form.Show ();
  933. form.Refresh ();
  934. form.Dispose ();
  935. }
  936. [Test] // bug #82041
  937. public void DontCallResumeLayout ()
  938. {
  939. Form form = new Form ();
  940. form.ShowInTaskbar = false;
  941. TableLayoutPanel tableLayoutPanel = new TableLayoutPanel ();
  942. form.Controls.Add (tableLayoutPanel);
  943. tableLayoutPanel.SuspendLayout ();
  944. tableLayoutPanel.ColumnCount = 3;
  945. tableLayoutPanel.Dock = DockStyle.Fill;
  946. tableLayoutPanel.RowCount = 11;
  947. tableLayoutPanel.Controls.Add (new Button ());
  948. form.Show ();
  949. form.Refresh ();
  950. form.Dispose ();
  951. }
  952. [Test] // bug #346246
  953. public void AutoSizePanelVerical ()
  954. {
  955. Form f = new Form ();
  956. f.ShowInTaskbar = false;
  957. TableLayoutPanel tlp = new TableLayoutPanel ();
  958. tlp.AutoSize = true;
  959. tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
  960. tlp.ColumnCount = 1;
  961. tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100F));
  962. tlp.Location = new Point (12, 12);
  963. tlp.Name = "tableLayoutPanel1";
  964. tlp.RowCount = 2;
  965. tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
  966. tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
  967. tlp.Size = new Size (139, 182);
  968. tlp.TabIndex = 0;
  969. f.Controls.Add (tlp);
  970. Button b = new Button ();
  971. b.Size = new Size (100, 100);
  972. tlp.Controls.Add (b, 0, 0);
  973. PictureBox p = new PictureBox ();
  974. p.Size = new Size (100, 100);
  975. tlp.Controls.Add (p,0,1);
  976. f.Show ();
  977. Assert.AreEqual (new Rectangle (12, 12, 106, 212), tlp.Bounds, "A1");
  978. Assert.AreEqual (new Rectangle (3, 3, 100, 100), b.Bounds, "A2");
  979. Assert.AreEqual (new Rectangle (3, 109, 100, 100), p.Bounds, "A3");
  980. b.Width += 20;
  981. b.Height += 20;
  982. Assert.AreEqual (new Rectangle (12, 12, 126, 252), tlp.Bounds, "B1");
  983. Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "B2");
  984. Assert.AreEqual (new Rectangle (3, 129, 100, 100), p.Bounds, "B3");
  985. p.Width += 20;
  986. p.Height += 20;
  987. Assert.AreEqual (new Rectangle (12, 12, 126, 252), tlp.Bounds, "C1");
  988. Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "C2");
  989. Assert.AreEqual (new Rectangle (3, 129, 120, 120), p.Bounds, "C3");
  990. f.Dispose ();
  991. }
  992. [Test] // bug #346246
  993. public void AutoSizePanelHorizontal ()
  994. {
  995. Form f = new Form ();
  996. f.ShowInTaskbar = false;
  997. TableLayoutPanel tlp = new TableLayoutPanel ();
  998. tlp.AutoSize = true;
  999. tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
  1000. tlp.ColumnCount = 2;
  1001. tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50F));
  1002. tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50F));
  1003. tlp.Location = new Point (12, 12);
  1004. tlp.Name = "tableLayoutPanel1";
  1005. tlp.RowCount = 1;
  1006. tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
  1007. tlp.Size = new Size (139, 182);
  1008. tlp.TabIndex = 0;
  1009. f.Controls.Add (tlp);
  1010. Button b = new Button ();
  1011. b.Size = new Size (100, 100);
  1012. tlp.Controls.Add (b, 0, 0);
  1013. PictureBox p = new PictureBox ();
  1014. p.Size = new Size (100, 100);
  1015. tlp.Controls.Add (p, 1, 0);
  1016. f.Show ();
  1017. Assert.AreEqual (new Rectangle (12, 12, 212, 106), tlp.Bounds, "A1");
  1018. Assert.AreEqual (new Rectangle (3, 3, 100, 100), b.Bounds, "A2");
  1019. Assert.AreEqual (new Rectangle (109, 3, 100, 100), p.Bounds, "A3");
  1020. b.Width += 20;
  1021. b.Height += 20;
  1022. Assert.AreEqual (new Rectangle (12, 12, 252, 126), tlp.Bounds, "B1");
  1023. Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "B2");
  1024. Assert.AreEqual (new Rectangle (129, 3, 100, 100), p.Bounds, "B3");
  1025. p.Width += 20;
  1026. p.Height += 20;
  1027. Assert.AreEqual (new Rectangle (12, 12, 252, 126), tlp.Bounds, "C1");
  1028. Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "C2");
  1029. Assert.AreEqual (new Rectangle (129, 3, 120, 120), p.Bounds, "C3");
  1030. f.Dispose ();
  1031. }
  1032. [Test]
  1033. public void Bug354676 ()
  1034. {
  1035. Form f = new Form ();
  1036. TableLayoutPanel tlp = new TableLayoutPanel ();
  1037. tlp.Dock = DockStyle.Fill;
  1038. tlp.Padding = new Padding (40);
  1039. tlp.RowCount = 2;
  1040. tlp.ColumnCount = 1;
  1041. f.Controls.Add (tlp);
  1042. Button b1 = new Button ();
  1043. tlp.Controls.Add (b1);
  1044. Button b2 = new Button ();
  1045. tlp.Controls.Add (b2);
  1046. f.Show ();
  1047. Assert.AreEqual (new Rectangle (43, 43, 75, 23), b1.Bounds, "A1");
  1048. Assert.AreEqual (new Rectangle (43, 72, 75, 23), b2.Bounds, "A2");
  1049. f.Close ();
  1050. f.Dispose ();
  1051. }
  1052. [Test]
  1053. public void Bug355408 ()
  1054. {
  1055. Form f = new Form ();
  1056. f.ClientSize = new Size (300, 300);
  1057. TableLayoutPanel tlp = new TableLayoutPanel ();
  1058. tlp.Dock = DockStyle.Fill;
  1059. tlp.RowCount = 2;
  1060. tlp.ColumnCount = 2;
  1061. f.Controls.Add (tlp);
  1062. Button b1 = new Button ();
  1063. tlp.Controls.Add (b1);
  1064. Button b2 = new Button ();
  1065. tlp.Controls.Add (b2);
  1066. Button b3 = new Button ();
  1067. b3.Dock = DockStyle.Fill;
  1068. b3.Width = 250;
  1069. tlp.SetColumnSpan (b3, 2);
  1070. tlp.Controls.Add (b3);
  1071. f.Show ();
  1072. Assert.AreEqual (new Rectangle (3, 3, 75, 23), b1.Bounds, "A1");
  1073. Assert.AreEqual (new Rectangle (84, 3, 75, 23), b2.Bounds, "A2");
  1074. Assert.AreEqual (new Rectangle (3, 32, 294, 265), b3.Bounds, "A3");
  1075. f.Close ();
  1076. f.Dispose ();
  1077. }
  1078. [Test]
  1079. public void Bug354672 ()
  1080. {
  1081. Form f = new Form ();
  1082. f.ClientSize = new Size (300, 300);
  1083. TableLayoutPanel tlp = new TableLayoutPanel ();
  1084. tlp.AutoSize = true;
  1085. tlp.ColumnCount = 2;
  1086. tlp.RowCount = 1;
  1087. f.Controls.Add (tlp);
  1088. TextBox t1 = new TextBox ();
  1089. t1.Dock = DockStyle.Fill;
  1090. tlp.Controls.Add (t1);
  1091. TextBox t2 = new TextBox ();
  1092. t2.Dock = DockStyle.Fill;
  1093. tlp.Controls.Add (t2);
  1094. Assert.AreEqual (new Size (212, t1.Height + 6), tlp.PreferredSize, "A1");
  1095. f.Dispose ();
  1096. }
  1097. [Test]
  1098. public void Bug354672More ()
  1099. {
  1100. Form f = new Form ();
  1101. f.ClientSize = new Size (300, 300);
  1102. TableLayoutPanel tlp = new TableLayoutPanel ();
  1103. tlp.AutoSize = true;
  1104. tlp.ColumnCount = 2;
  1105. tlp.RowCount = 1;
  1106. tlp.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
  1107. tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50f));
  1108. f.Controls.Add (tlp);
  1109. TextBox t1 = new TextBox ();
  1110. t1.Dock = DockStyle.Fill;
  1111. tlp.Controls.Add (t1);
  1112. TextBox t2 = new TextBox ();
  1113. t2.Dock = DockStyle.Fill;
  1114. tlp.Controls.Add (t2);
  1115. Assert.AreEqual (new Size (212, t1.Height + 6), tlp.PreferredSize, "A1");
  1116. f.Dispose ();
  1117. }
  1118. }
  1119. }
  1120. #endif