| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382 |
- //
- // TableLayoutTests.cs
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // Copyright (c) 2006 Jonathan Pobst
- //
- // Authors:
- // Jonathan Pobst ([email protected])
- //
- #if NET_2_0
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using NUnit.Framework;
- namespace MonoTests.System.Windows.Forms
- {
- [TestFixture]
- public class TableLayoutTests
- {
- [Test]
- public void TestConstruction ()
- {
- TableLayoutPanel p = new TableLayoutPanel ();
- Assert.AreEqual (BorderStyle.None, p.BorderStyle, "A1");
- Assert.AreEqual (TableLayoutPanelCellBorderStyle.None, p.CellBorderStyle, "A2");
- Assert.AreEqual (0, p.ColumnCount, "A3");
- Assert.AreEqual (TableLayoutPanelGrowStyle.AddRows, p.GrowStyle, "A4");
- Assert.AreEqual ("System.Windows.Forms.Layout.TableLayout", p.LayoutEngine.ToString (), "A5");
- Assert.AreEqual ("System.Windows.Forms.TableLayoutSettings", p.LayoutSettings.ToString (), "A6");
- Assert.AreEqual (0, p.RowCount, "A7");
- Assert.AreEqual (0, p.ColumnStyles.Count, "A8");
- Assert.AreEqual (0, p.RowStyles.Count, "A9");
- Assert.AreEqual (new Size (200, 100), p.Size, "A10");
- }
- [Test]
- public void TestPropertySetters ()
- {
- TableLayoutPanel p = new TableLayoutPanel ();
- p.BorderStyle = BorderStyle.Fixed3D;
- p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;
- p.ColumnCount = 1;
- p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;
- p.RowCount = 1;
- Assert.AreEqual (BorderStyle.Fixed3D, p.BorderStyle, "A1");
- Assert.AreEqual (TableLayoutPanelCellBorderStyle.OutsetDouble, p.CellBorderStyle, "A2");
- Assert.AreEqual (1, p.ColumnCount, "A3");
- Assert.AreEqual (TableLayoutPanelGrowStyle.FixedSize, p.GrowStyle, "A4");
- Assert.AreEqual (1, p.RowCount, "A7");
- }
- [Test]
- public void TestExtenderMethods ()
- {
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c = new Button ();
- Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetCellPosition (c), "A1");
- Assert.AreEqual (-1, p.GetColumn (c), "A2");
- Assert.AreEqual (1, p.GetColumnSpan (c), "A3");
- Assert.AreEqual (-1, p.GetRow (c), "A4");
- Assert.AreEqual (1, p.GetRowSpan (c), "A5");
- p.SetCellPosition (c, new TableLayoutPanelCellPosition (1, 1));
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetCellPosition (c), "A6");
- p.SetColumn (c, 2);
- Assert.AreEqual (2, p.GetColumn (c), "A7");
- p.SetRow (c, 2);
- Assert.AreEqual (2, p.GetRow (c), "A9");
- p.SetColumnSpan (c, 2);
- Assert.AreEqual (2, p.GetColumnSpan (c), "A8");
- p.SetRowSpan (c, 2);
- Assert.AreEqual (2, p.GetRowSpan (c), "A10");
- Assert.AreEqual (new TableLayoutPanelCellPosition (2, 2), p.GetCellPosition (c), "A11");
- // ???????
- //Assert.AreEqual (new TableLayoutPanelCellPosition (-1, -1), p.GetPositionFromControl (c), "A12");
- //Assert.AreEqual (c, p.GetControlFromPosition(0, 0), "A13");
- }
- [Test]
- public void TestColumnStyles ()
- {
- TableLayoutPanel p = new TableLayoutPanel ();
- p.ColumnStyles.Add (new ColumnStyle ());
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 20F));
- Assert.AreEqual (3, p.ColumnStyles.Count, "A1");
- Assert.AreEqual (SizeType.AutoSize, p.ColumnStyles[0].SizeType, "A2");
- Assert.AreEqual (0, p.ColumnStyles[0].Width, "A3");
- Assert.AreEqual (SizeType.Absolute, p.ColumnStyles[1].SizeType, "A4");
- Assert.AreEqual (0, p.ColumnStyles[1].Width, "A5");
- Assert.AreEqual (SizeType.Percent, p.ColumnStyles[2].SizeType, "A6");
- Assert.AreEqual (20F, p.ColumnStyles[2].Width, "A7");
- p.ColumnStyles.Remove (p.ColumnStyles[0]);
- Assert.AreEqual (2, p.ColumnStyles.Count, "A8");
- Assert.AreEqual (SizeType.Absolute, p.ColumnStyles[0].SizeType, "A9");
- Assert.AreEqual (0, p.ColumnStyles[0].Width, "A10");
- Assert.AreEqual (SizeType.Percent, p.ColumnStyles[1].SizeType, "A11");
- Assert.AreEqual (20F, p.ColumnStyles[1].Width, "A12");
- }
- [Test]
- public void TestRowStyles ()
- {
- TableLayoutPanel p = new TableLayoutPanel ();
- p.RowStyles.Add (new RowStyle ());
- p.RowStyles.Add (new RowStyle (SizeType.Absolute));
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 20F));
- Assert.AreEqual (3, p.RowStyles.Count, "A1");
- Assert.AreEqual (SizeType.AutoSize, p.RowStyles[0].SizeType, "A2");
- Assert.AreEqual (0, p.RowStyles[0].Height, "A3");
- Assert.AreEqual (SizeType.Absolute, p.RowStyles[1].SizeType, "A4");
- Assert.AreEqual (0, p.RowStyles[1].Height, "A5");
- Assert.AreEqual (SizeType.Percent, p.RowStyles[2].SizeType, "A6");
- Assert.AreEqual (20F, p.RowStyles[2].Height, "A7");
- p.RowStyles.Remove (p.RowStyles[0]);
- Assert.AreEqual (2, p.RowStyles.Count, "A8");
- Assert.AreEqual (SizeType.Absolute, p.RowStyles[0].SizeType, "A9");
- Assert.AreEqual (0, p.RowStyles[0].Height, "A10");
- Assert.AreEqual (SizeType.Percent, p.RowStyles[1].SizeType, "A11");
- Assert.AreEqual (20F, p.RowStyles[1].Height, "A12");
- }
- [Test]
- public void TestColumnStyles3 ()
- {
- // Don't lose the 2nd style
- TableLayoutPanel p = new TableLayoutPanel ();
- p.ColumnCount = 2;
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));
- p.ColumnCount = 1;
- Assert.AreEqual (2, p.ColumnStyles.Count, "A1");
- }
- [Test]
- public void TestColumnStyles2 ()
- {
- // Don't lose the 2nd style
- TableLayoutPanel p = new TableLayoutPanel ();
- p.ColumnCount = 1;
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20F));
- p.ColumnCount = 2;
- Assert.AreEqual (1, p.ColumnStyles.Count, "A2");
- }
- [Test]
- public void TestCellPositioning ()
- {
- // Standard Add
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- Control c4 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- p.Controls.Add (c4);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c4), "C4");
- }
- [Test]
- public void TestCellPositioning2 ()
- {
- // Growstyle = Add Rows
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- Control c4 = new Button ();
- Control c5 = new Button ();
- Control c6 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- p.Controls.Add (c4);
- p.Controls.Add (c5);
- p.Controls.Add (c6);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c4), "C4");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 2), p.GetPositionFromControl (c5), "C5");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 2), p.GetPositionFromControl (c6), "C6");
- }
- [Test]
- public void TestCellPositioning3 ()
- {
- // Growstyle = Add Columns
- TableLayoutPanel p = new TableLayoutPanel ();
- p.GrowStyle = TableLayoutPanelGrowStyle.AddColumns;
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- Control c4 = new Button ();
- Control c5 = new Button ();
- Control c6 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- p.Controls.Add (c4);
- p.Controls.Add (c5);
- p.Controls.Add (c6);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (2, 0), p.GetPositionFromControl (c3), "C3");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c4), "C4");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c5), "C5");
- Assert.AreEqual (new TableLayoutPanelCellPosition (2, 1), p.GetPositionFromControl (c6), "C6");
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))]
- public void TestCellPositioning4 ()
- {
- // Growstyle = Fixed Size
- TableLayoutPanel p = new TableLayoutPanel ();
- p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- Control c4 = new Button ();
- Control c5 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- p.Controls.Add (c4);
- p.Controls.Add (c5);
- }
- [Test]
- public void TestCellPositioning5 ()
- {
- // One control have fixed position
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- Control c4 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.SetCellPosition (c4, new TableLayoutPanelCellPosition (0, 0));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- p.Controls.Add (c4);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c4), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c1), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c2), "C3");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c3), "C4");
- }
- [Test]
- public void TestCellPositioning6 ()
- {
- // One control has fixed column, it should be ignored
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- Control c4 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.SetColumn (c3, 1);
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- p.Controls.Add (c4);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c4), "C4");
- }
- [Test]
- public void TestCellPositioning7 ()
- {
- // One control has fixed column and row
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- Control c4 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.SetColumn (c3, 1);
- p.SetRow (c3, 1);
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- p.Controls.Add (c4);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c3), "C3");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c4), "C4");
- }
- [Test]
- public void TestCellPositioning8 ()
- {
- // Column span
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.SetColumnSpan (c1, 2);
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c3), "C3");
- }
- [Test]
- public void TestCellPositioning9 ()
- {
- // Row span
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.SetRowSpan (c1, 2);
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 1), p.GetPositionFromControl (c3), "C3");
- }
- [Test]
- public void TestCellPositioning10 ()
- {
- // Column span = 2, but control is in the last column, forces control back into 1st column, next row
- // I have no clue why c3 shouldn't be in (1,0), but MS says it's not
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.SetColumnSpan (c2, 2);
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 2), p.GetPositionFromControl (c3), "C3");
- }
- [Test]
- public void TestCellPositioning11 ()
- {
- // Row span = 2, but control is in the last row, creates new row
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.SetRowSpan (c3, 2);
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
- }
- [Test]
- public void TestCellPositioning12 ()
- {
- // Requesting a column greater than ColumnCount, request is ignored
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.SetColumn (c1, 4);
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
- }
- [Test]
- public void TestCellPositioning13 ()
- {
- // Row span = 2, but control is in the last row, creates new row
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 3;
- p.RowCount = 2;
- p.SetRowSpan (c3, 2);
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (2, 0), p.GetPositionFromControl (c3), "C3");
- }
- [Test]
- [Category ("NotWorking")]
- public void TestCellPositioning14 ()
- {
- // Col span = 3, fixed grow style
- TableLayoutPanel p = new TableLayoutPanel ();
- p.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;
- Control c1 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.SetColumnSpan (c1, 3);
- p.Controls.Add (c1);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- }
- [Test]
- public void TestCellPositioning15 ()
- {
- // Column span = 2, but control is in the last column, forces control back into 1st column, next row
- // I have no clue why c3 shouldn't be in (1,0), but MS says it's not
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.SetColumnSpan (c2, 2);
- p.SetCellPosition (c2, new TableLayoutPanelCellPosition (1, 0));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 2), p.GetPositionFromControl (c3), "C3");
- }
- [Test]
- public void TestCellPositioning16 ()
- {
- // Row span = 2, but control is in the last row, creates new row
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.SetRowSpan (c3, 2);
- p.SetCellPosition (c3, new TableLayoutPanelCellPosition (0, 1));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 0), p.GetPositionFromControl (c1), "C1");
- Assert.AreEqual (new TableLayoutPanelCellPosition (1, 0), p.GetPositionFromControl (c2), "C2");
- Assert.AreEqual (new TableLayoutPanelCellPosition (0, 1), p.GetPositionFromControl (c3), "C3");
- }
- [Test]
- public void TestRowColumnSizes1 ()
- {
- // Row span = 2, but control is in the last row, creates new row
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 1;
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (71, p.GetRowHeights ()[0], "D1");
- Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
- }
- [Test]
- public void TestRowColumnSizes2 ()
- {
- // Row span = 2, but control is in the last row, creates new row
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 1;
- p.RowStyles.Add (new RowStyle (SizeType.Absolute, 100F));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (100, p.GetRowHeights ()[0], "D1");
- Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
- }
- [Test]
- public void TestRowColumnSizes3 ()
- {
- // Row span = 2, but control is in the last row, creates new row
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- Control c4 = new Button ();
- Control c5 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 1;
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- p.Controls.Add (c4);
- p.Controls.Add (c5);
- Assert.AreEqual (42, p.GetRowHeights ()[0], "D1");
- Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
- Assert.AreEqual (29, p.GetRowHeights ()[2], "D3");
- }
- [Test]
- public void TestRowColumnSizes4 ()
- {
- // Row span = 2, but control is in the last row, creates new row
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- Control c4 = new Button ();
- Control c5 = new Button ();
- Control c6 = new Button ();
- Control c7 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 1;
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- p.Controls.Add (c4);
- p.Controls.Add (c5);
- p.Controls.Add (c6);
- p.Controls.Add (c7);
- //Assert.AreEqual (100, p.GetRowHeights ()[0], "D1");
- Assert.AreEqual (29, p.GetRowHeights ()[1], "D2");
- Assert.AreEqual (29, p.GetRowHeights ()[2], "D3");
- Assert.AreEqual (29, p.GetRowHeights ()[3], "D4");
- }
- [Test]
- public void TestRowColumnSizes5 ()
- {
- // 2 Absolute Columns/Rows
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.RowStyles.Add (new RowStyle (SizeType.Absolute, 20));
- p.RowStyles.Add (new RowStyle (SizeType.Absolute, 30));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 20));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 30));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (20, p.GetRowHeights ()[0], "D1");
- Assert.AreEqual (80, p.GetRowHeights ()[1], "D2");
- Assert.AreEqual (20, p.GetColumnWidths ()[0], "D3");
- Assert.AreEqual (180, p.GetColumnWidths ()[1], "D4");
- }
- [Test]
- public void TestRowColumnSizes6 ()
- {
- // 2 50% Columns/Rows
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
- Assert.AreEqual (50, p.GetRowHeights ()[1], "D2");
- Assert.AreEqual (100, p.GetColumnWidths ()[0], "D3");
- Assert.AreEqual (100, p.GetColumnWidths ()[1], "D4");
- }
- [Test]
- public void TestRowColumnSizes7 ()
- {
- // 1 Absolute and 2 Percent Columns/Rows
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 3;
- p.RowCount = 3;
- p.RowStyles.Add (new RowStyle (SizeType.Absolute, 50));
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 50));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 50));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
- Assert.AreEqual (25, p.GetRowHeights ()[1], "D2");
- Assert.AreEqual (25, p.GetRowHeights ()[2], "D3");
- Assert.AreEqual (50, p.GetColumnWidths ()[0], "D4");
- Assert.AreEqual (75, p.GetColumnWidths ()[1], "D5");
- Assert.AreEqual (75, p.GetColumnWidths ()[2], "D6");
- }
- [Test]
- public void TestRowColumnSizes8 ()
- {
- // 1 Absolute and 2 Percent Columns/Rows (with total percents > 100)
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 3;
- p.RowCount = 3;
- p.RowStyles.Add (new RowStyle (SizeType.Absolute, 50));
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 100));
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 100));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 50));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
- Assert.AreEqual (25, p.GetRowHeights ()[1], "D2");
- Assert.AreEqual (25, p.GetRowHeights ()[2], "D3");
- Assert.AreEqual (50, p.GetColumnWidths ()[0], "D4");
- Assert.AreEqual (75, p.GetColumnWidths ()[1], "D5");
- Assert.AreEqual (75, p.GetColumnWidths ()[2], "D6");
- }
- [Test]
- public void TestRowColumnSizes9 ()
- {
- // 1 Absolute and 2 Percent Columns/Rows (with total percents > 100)
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 3;
- p.RowCount = 3;
- p.RowStyles.Add (new RowStyle (SizeType.Absolute, 50));
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 80));
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 40));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 50));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 80));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 40));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (50, p.GetRowHeights ()[0], "D1");
- Assert.AreEqual (33, p.GetRowHeights ()[1], "D2");
- Assert.AreEqual (17, p.GetRowHeights ()[2], "D3");
- Assert.AreEqual (50, p.GetColumnWidths ()[0], "D4");
- Assert.AreEqual (100, p.GetColumnWidths ()[1], "D5");
- Assert.AreEqual (50, p.GetColumnWidths ()[2], "D6");
- }
- [Test]
- public void TestRowColumnSizes10 ()
- {
- // 2 AutoSize Columns/Rows
- TableLayoutPanel p = new TableLayoutPanel ();
- Control c1 = new Button ();
- Control c2 = new Button ();
- Control c3 = new Button ();
- p.ColumnCount = 2;
- p.RowCount = 2;
- p.RowStyles.Add (new RowStyle (SizeType.AutoSize));
- p.RowStyles.Add (new RowStyle (SizeType.AutoSize));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
- p.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
- p.Controls.Add (c1);
- p.Controls.Add (c2);
- p.Controls.Add (c3);
- Assert.AreEqual (29, p.GetRowHeights ()[0], "D1");
- Assert.AreEqual (71, p.GetRowHeights ()[1], "D2");
- Assert.AreEqual (81, p.GetColumnWidths ()[0], "D3");
- Assert.AreEqual (119, p.GetColumnWidths ()[1], "D4");
- }
-
- [Test]
- public void Bug81843 ()
- {
- Form f = new Form ();
- f.ShowInTaskbar = false;
-
- TableLayoutPanel tableLayoutPanel1;
- Button button2;
- TextBox textBox1;
- Button button4;
- tableLayoutPanel1 = new TableLayoutPanel ();
- button2 = new Button ();
- button4 = new Button ();
- textBox1 = new TextBox ();
- tableLayoutPanel1.SuspendLayout ();
- f.SuspendLayout ();
- tableLayoutPanel1.AutoSize = true;
- tableLayoutPanel1.ColumnCount = 3;
- tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
- tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
- tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
- tableLayoutPanel1.Controls.Add (button2, 0, 1);
- tableLayoutPanel1.Controls.Add (button4, 2, 1);
- tableLayoutPanel1.Controls.Add (textBox1, 1, 0);
- tableLayoutPanel1.Location = new Point (0, 0);
- tableLayoutPanel1.RowCount = 2;
- tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
- tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
- tableLayoutPanel1.Size = new Size (292, 287);
- button2.Size = new Size (75, 23);
-
- button4.Size = new Size (75, 23);
- textBox1.Dock = DockStyle.Fill;
- textBox1.Location = new Point (84, 3);
- textBox1.Multiline = true;
- textBox1.Size = new Size (94, 137);
- f.ClientSize = new Size (292, 312);
- f.Controls.Add (tableLayoutPanel1);
- f.Name = "Form1";
- f.Text = "Form1";
- tableLayoutPanel1.ResumeLayout (false);
- tableLayoutPanel1.PerformLayout ();
- f.ResumeLayout (false);
- f.PerformLayout ();
- f.Show ();
- Assert.AreEqual (new Rectangle (3, 146, 75, 23), button2.Bounds, "A1");
- Assert.AreEqual (new Rectangle (184, 146, 75, 23), button4.Bounds, "A2");
- Assert.AreEqual (new Rectangle (84, 3, 94, 137), textBox1.Bounds, "A3");
-
- f.Dispose ();
- }
-
- [Test] // From bug #81884
- public void CellBorderStyle ()
- {
- Form f = new Form ();
- f.ShowInTaskbar = false;
- TableLayoutPanel p = new TableLayoutPanel ();
- p = new TableLayoutPanel ();
- p.ColumnCount = 3;
- p.ColumnStyles.Add (new ColumnStyle ());
- p.ColumnStyles.Add (new ColumnStyle ());
- p.ColumnStyles.Add (new ColumnStyle ());
- p.Dock = DockStyle.Top;
- p.Height = 200;
- p.RowCount = 2;
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
- p.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
- f.Controls.Add (p);
- Label _labelA = new Label ();
- _labelA.Dock = DockStyle.Fill;
- _labelA.Size = new Size (95, 20);
- _labelA.Text = "A";
- p.Controls.Add (_labelA, 0, 0);
- Label _labelB = new Label ();
- _labelB.Dock = DockStyle.Fill;
- _labelB.Size = new Size (95, 20);
- _labelB.Text = "B";
- p.Controls.Add (_labelB, 1, 0);
- Label _labelC = new Label ();
- _labelC.Dock = DockStyle.Fill;
- _labelC.Size = new Size (95, 20);
- _labelC.Text = "C";
- p.Controls.Add (_labelC, 2, 0);
- Label _labelD = new Label ();
- _labelD.Dock = DockStyle.Fill;
- _labelD.Size = new Size (95, 20);
- _labelD.Text = "D";
- p.Controls.Add (_labelD, 0, 1);
- Label _labelE = new Label ();
- _labelE.Dock = DockStyle.Fill;
- _labelE.Size = new Size (95, 20);
- _labelE.Text = "E";
- p.Controls.Add (_labelE, 1, 1);
- Label _labelF = new Label ();
- _labelF.Dock = DockStyle.Fill;
- _labelF.Size = new Size (95, 20);
- _labelF.Text = "F";
- p.Controls.Add (_labelF, 2, 1);
- _labelA.BackColor = Color.Red;
- _labelB.BackColor = Color.Orange;
- _labelC.BackColor = Color.Yellow;
- _labelD.BackColor = Color.Green;
- _labelE.BackColor = Color.Blue;
- _labelF.BackColor = Color.Purple;
- f.Show ();
- // None
- Assert.AreEqual (new Rectangle (3, 0, 95, 100), _labelA.Bounds, "A1");
- Assert.AreEqual (new Rectangle (104, 0, 95, 100), _labelB.Bounds, "A2");
- Assert.AreEqual (new Rectangle (205, 0, 95, 100), _labelC.Bounds, "A3");
- Assert.AreEqual (new Rectangle (3, 100, 95, 100), _labelD.Bounds, "A4");
- Assert.AreEqual (new Rectangle (104, 100, 95, 100), _labelE.Bounds, "A5");
- Assert.AreEqual (new Rectangle (205, 100, 95, 100), _labelF.Bounds, "A6");
-
- p.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
- Assert.AreEqual (new Rectangle (4, 1, 95, 98), _labelA.Bounds, "A7");
- Assert.AreEqual (new Rectangle (106, 1, 95, 98), _labelB.Bounds, "A8");
- Assert.AreEqual (new Rectangle (208, 1, 95, 98), _labelC.Bounds, "A9");
- Assert.AreEqual (new Rectangle (4, 100, 95, 99), _labelD.Bounds, "A10");
- Assert.AreEqual (new Rectangle (106, 100, 95, 99), _labelE.Bounds, "A11");
- Assert.AreEqual (new Rectangle (208, 100, 95, 99), _labelF.Bounds, "A12");
- p.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset;
- Assert.AreEqual (new Rectangle (5, 2, 95, 97), _labelA.Bounds, "A13");
- Assert.AreEqual (new Rectangle (108, 2, 95, 97), _labelB.Bounds, "A14");
- Assert.AreEqual (new Rectangle (211, 2, 95, 97), _labelC.Bounds, "A15");
- Assert.AreEqual (new Rectangle (5, 101, 95, 97), _labelD.Bounds, "A16");
- Assert.AreEqual (new Rectangle (108, 101, 95, 97), _labelE.Bounds, "A17");
- Assert.AreEqual (new Rectangle (211, 101, 95, 97), _labelF.Bounds, "A18");
- p.CellBorderStyle = TableLayoutPanelCellBorderStyle.InsetDouble;
- Assert.AreEqual (new Rectangle (6, 3, 95, 95), _labelA.Bounds, "A19");
- Assert.AreEqual (new Rectangle (110, 3, 95, 95), _labelB.Bounds, "A20");
- Assert.AreEqual (new Rectangle (214, 3, 95, 95), _labelC.Bounds, "A21");
- Assert.AreEqual (new Rectangle (6, 101, 95, 96), _labelD.Bounds, "A22");
- Assert.AreEqual (new Rectangle (110, 101, 95, 96), _labelE.Bounds, "A23");
- Assert.AreEqual (new Rectangle (214, 101, 95, 96), _labelF.Bounds, "A24");
- p.CellBorderStyle = TableLayoutPanelCellBorderStyle.Outset;
- Assert.AreEqual (new Rectangle (5, 2, 95, 97), _labelA.Bounds, "A25");
- Assert.AreEqual (new Rectangle (108, 2, 95, 97), _labelB.Bounds, "A26");
- Assert.AreEqual (new Rectangle (211, 2, 95, 97), _labelC.Bounds, "A27");
- Assert.AreEqual (new Rectangle (5, 101, 95, 97), _labelD.Bounds, "A28");
- Assert.AreEqual (new Rectangle (108, 101, 95, 97), _labelE.Bounds, "A29");
- Assert.AreEqual (new Rectangle (211, 101, 95, 97), _labelF.Bounds, "A30");
- p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetDouble;
- Assert.AreEqual (new Rectangle (6, 3, 95, 95), _labelA.Bounds, "A31");
- Assert.AreEqual (new Rectangle (110, 3, 95, 95), _labelB.Bounds, "A32");
- Assert.AreEqual (new Rectangle (214, 3, 95, 95), _labelC.Bounds, "A33");
- Assert.AreEqual (new Rectangle (6, 101, 95, 96), _labelD.Bounds, "A34");
- Assert.AreEqual (new Rectangle (110, 101, 95, 96), _labelE.Bounds, "A35");
- Assert.AreEqual (new Rectangle (214, 101, 95, 96), _labelF.Bounds, "A36");
- p.CellBorderStyle = TableLayoutPanelCellBorderStyle.OutsetPartial;
- Assert.AreEqual (new Rectangle (6, 3, 95, 95), _labelA.Bounds, "A37");
- Assert.AreEqual (new Rectangle (110, 3, 95, 95), _labelB.Bounds, "A38");
- Assert.AreEqual (new Rectangle (214, 3, 95, 95), _labelC.Bounds, "A39");
- Assert.AreEqual (new Rectangle (6, 101, 95, 96), _labelD.Bounds, "A40");
- Assert.AreEqual (new Rectangle (110, 101, 95, 96), _labelE.Bounds, "A41");
- Assert.AreEqual (new Rectangle (214, 101, 95, 96), _labelF.Bounds, "A42");
-
- f.Close ();
- }
- [Test]
- public void Bug81936 ()
- {
- Form f = new Form ();
- f.ShowInTaskbar = false;
- TableLayoutPanel tableLayoutPanel1;
- Label button2;
- Label button4;
- tableLayoutPanel1 = new TableLayoutPanel ();
- button2 = new Label ();
- button4 = new Label ();
- button2.Text = "Test1";
- button4.Text = "Test2";
- button2.Anchor = AnchorStyles.Left;
- button4.Anchor = AnchorStyles.Left;
- button2.Height = 14;
- button4.Height = 14;
- tableLayoutPanel1.SuspendLayout ();
- f.SuspendLayout ();
- tableLayoutPanel1.ColumnCount = 1;
- tableLayoutPanel1.ColumnStyles.Add (new ColumnStyle ());
- tableLayoutPanel1.Controls.Add (button2, 0, 0);
- tableLayoutPanel1.Controls.Add (button4, 0, 1);
- tableLayoutPanel1.Location = new Point (0, 0);
- tableLayoutPanel1.RowCount = 2;
- tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Absolute, 28F));
- tableLayoutPanel1.RowStyles.Add (new RowStyle (SizeType.Absolute, 28F));
- tableLayoutPanel1.Size = new Size (292, 56);
- f.ClientSize = new Size (292, 312);
- f.Controls.Add (tableLayoutPanel1);
- f.Name = "Form1";
- f.Text = "Form1";
- tableLayoutPanel1.ResumeLayout (false);
- tableLayoutPanel1.PerformLayout ();
- f.ResumeLayout (false);
- f.PerformLayout ();
- f.Show ();
- Assert.AreEqual (new Rectangle (3, 7, 100, 14), button2.Bounds, "A1");
- Assert.AreEqual (new Rectangle (3, 35, 100, 14), button4.Bounds, "A2");
- f.Dispose ();
- }
- [Test]
- public void Bug82605 ()
- {
- Form f = new Form ();
- f.ShowInTaskbar = false;
-
- Label l = new Label ();
- TableLayoutPanel table = new TableLayoutPanel ();
- table.ColumnCount = 1;
- table.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100F));
- table.RowCount = 2;
- table.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
- table.RowStyles.Add (new RowStyle (SizeType.Absolute, 20F));
- table.Controls.Add (l, 0, 1);
- table.Location = new Point (0, 0);
- table.Width = 250;
- l.Anchor = AnchorStyles.Left | AnchorStyles.Right;
- l.AutoSize = true;
- l.Location = new Point (3, 352);
- l.Size = new Size (578, 13);
- l.Text = "label1";
- l.TextAlign = ContentAlignment.MiddleCenter;
- f.Controls.Add (table);
- f.Show ();
-
- // Height is font dependent, but this bug is about the width anyways
- Assert.AreEqual (244, l.Width, "A1");
- }
-
- [Test] // bug #82040
- public void ShowNoChildren ()
- {
- Form form = new Form ();
- form.ShowInTaskbar = false;
- TableLayoutPanel tableLayoutPanel = new TableLayoutPanel ();
- tableLayoutPanel.ColumnCount = 3;
- tableLayoutPanel.Dock = DockStyle.Fill;
- tableLayoutPanel.RowCount = 11;
- form.Controls.Add (tableLayoutPanel);
- form.Show ();
- form.Refresh ();
- form.Dispose ();
- }
- [Test] // bug #82041
- public void DontCallResumeLayout ()
- {
- Form form = new Form ();
- form.ShowInTaskbar = false;
- TableLayoutPanel tableLayoutPanel = new TableLayoutPanel ();
- form.Controls.Add (tableLayoutPanel);
- tableLayoutPanel.SuspendLayout ();
- tableLayoutPanel.ColumnCount = 3;
- tableLayoutPanel.Dock = DockStyle.Fill;
- tableLayoutPanel.RowCount = 11;
- tableLayoutPanel.Controls.Add (new Button ());
- form.Show ();
- form.Refresh ();
- form.Dispose ();
- }
-
- [Test] // bug #346246
- public void AutoSizePanelVerical ()
- {
- Form f = new Form ();
- f.ShowInTaskbar = false;
-
- TableLayoutPanel tlp = new TableLayoutPanel ();
- tlp.AutoSize = true;
- tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
- tlp.ColumnCount = 1;
- tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100F));
- tlp.Location = new Point (12, 12);
- tlp.Name = "tableLayoutPanel1";
- tlp.RowCount = 2;
- tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
- tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 50F));
- tlp.Size = new Size (139, 182);
- tlp.TabIndex = 0;
- f.Controls.Add (tlp);
- Button b = new Button ();
- b.Size = new Size (100, 100);
- tlp.Controls.Add (b, 0, 0);
- PictureBox p = new PictureBox ();
- p.Size = new Size (100, 100);
- tlp.Controls.Add (p,0,1);
-
- f.Show ();
- Assert.AreEqual (new Rectangle (12, 12, 106, 212), tlp.Bounds, "A1");
- Assert.AreEqual (new Rectangle (3, 3, 100, 100), b.Bounds, "A2");
- Assert.AreEqual (new Rectangle (3, 109, 100, 100), p.Bounds, "A3");
-
- b.Width += 20;
- b.Height += 20;
- Assert.AreEqual (new Rectangle (12, 12, 126, 252), tlp.Bounds, "B1");
- Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "B2");
- Assert.AreEqual (new Rectangle (3, 129, 100, 100), p.Bounds, "B3");
- p.Width += 20;
- p.Height += 20;
- Assert.AreEqual (new Rectangle (12, 12, 126, 252), tlp.Bounds, "C1");
- Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "C2");
- Assert.AreEqual (new Rectangle (3, 129, 120, 120), p.Bounds, "C3");
-
- f.Dispose ();
- }
- [Test] // bug #346246
- public void AutoSizePanelHorizontal ()
- {
- Form f = new Form ();
- f.ShowInTaskbar = false;
- TableLayoutPanel tlp = new TableLayoutPanel ();
- tlp.AutoSize = true;
- tlp.AutoSizeMode = AutoSizeMode.GrowAndShrink;
- tlp.ColumnCount = 2;
- tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50F));
- tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50F));
- tlp.Location = new Point (12, 12);
- tlp.Name = "tableLayoutPanel1";
- tlp.RowCount = 1;
- tlp.RowStyles.Add (new RowStyle (SizeType.Percent, 100F));
- tlp.Size = new Size (139, 182);
- tlp.TabIndex = 0;
- f.Controls.Add (tlp);
- Button b = new Button ();
- b.Size = new Size (100, 100);
- tlp.Controls.Add (b, 0, 0);
- PictureBox p = new PictureBox ();
- p.Size = new Size (100, 100);
- tlp.Controls.Add (p, 1, 0);
- f.Show ();
- Assert.AreEqual (new Rectangle (12, 12, 212, 106), tlp.Bounds, "A1");
- Assert.AreEqual (new Rectangle (3, 3, 100, 100), b.Bounds, "A2");
- Assert.AreEqual (new Rectangle (109, 3, 100, 100), p.Bounds, "A3");
- b.Width += 20;
- b.Height += 20;
- Assert.AreEqual (new Rectangle (12, 12, 252, 126), tlp.Bounds, "B1");
- Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "B2");
- Assert.AreEqual (new Rectangle (129, 3, 100, 100), p.Bounds, "B3");
- p.Width += 20;
- p.Height += 20;
- Assert.AreEqual (new Rectangle (12, 12, 252, 126), tlp.Bounds, "C1");
- Assert.AreEqual (new Rectangle (3, 3, 120, 120), b.Bounds, "C2");
- Assert.AreEqual (new Rectangle (129, 3, 120, 120), p.Bounds, "C3");
- f.Dispose ();
- }
-
- [Test]
- public void Bug354676 ()
- {
- Form f = new Form ();
- TableLayoutPanel tlp = new TableLayoutPanel ();
- tlp.Dock = DockStyle.Fill;
- tlp.Padding = new Padding (40);
- tlp.RowCount = 2;
- tlp.ColumnCount = 1;
- f.Controls.Add (tlp);
- Button b1 = new Button ();
- tlp.Controls.Add (b1);
- Button b2 = new Button ();
- tlp.Controls.Add (b2);
- f.Show ();
- Assert.AreEqual (new Rectangle (43, 43, 75, 23), b1.Bounds, "A1");
- Assert.AreEqual (new Rectangle (43, 72, 75, 23), b2.Bounds, "A2");
-
- f.Close ();
- f.Dispose ();
- }
-
- [Test]
- public void Bug355408 ()
- {
- Form f = new Form ();
- f.ClientSize = new Size (300, 300);
-
- TableLayoutPanel tlp = new TableLayoutPanel ();
- tlp.Dock = DockStyle.Fill;
- tlp.RowCount = 2;
- tlp.ColumnCount = 2;
- f.Controls.Add (tlp);
- Button b1 = new Button ();
- tlp.Controls.Add (b1);
- Button b2 = new Button ();
- tlp.Controls.Add (b2);
-
- Button b3 = new Button ();
- b3.Dock = DockStyle.Fill;
- b3.Width = 250;
- tlp.SetColumnSpan (b3, 2);
- tlp.Controls.Add (b3);
- f.Show ();
- Assert.AreEqual (new Rectangle (3, 3, 75, 23), b1.Bounds, "A1");
- Assert.AreEqual (new Rectangle (84, 3, 75, 23), b2.Bounds, "A2");
- Assert.AreEqual (new Rectangle (3, 32, 294, 265), b3.Bounds, "A3");
- f.Close ();
- f.Dispose ();
- }
-
- [Test]
- public void Bug354672 ()
- {
- Form f = new Form ();
- f.ClientSize = new Size (300, 300);
- TableLayoutPanel tlp = new TableLayoutPanel ();
- tlp.AutoSize = true;
- tlp.ColumnCount = 2;
- tlp.RowCount = 1;
- f.Controls.Add (tlp);
- TextBox t1 = new TextBox ();
- t1.Dock = DockStyle.Fill;
- tlp.Controls.Add (t1);
- TextBox t2 = new TextBox ();
- t2.Dock = DockStyle.Fill;
- tlp.Controls.Add (t2);
- Assert.AreEqual (new Size (212, t1.Height + 6), tlp.PreferredSize, "A1");
- f.Dispose ();
- }
- [Test]
- public void Bug354672More ()
- {
- Form f = new Form ();
- f.ClientSize = new Size (300, 300);
- TableLayoutPanel tlp = new TableLayoutPanel ();
- tlp.AutoSize = true;
- tlp.ColumnCount = 2;
- tlp.RowCount = 1;
- tlp.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
- tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 50f));
-
- f.Controls.Add (tlp);
- TextBox t1 = new TextBox ();
- t1.Dock = DockStyle.Fill;
- tlp.Controls.Add (t1);
- TextBox t2 = new TextBox ();
- t2.Dock = DockStyle.Fill;
- tlp.Controls.Add (t2);
- Assert.AreEqual (new Size (212, t1.Height + 6), tlp.PreferredSize, "A1");
- f.Dispose ();
- }
- }
- }
- #endif
|