| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864 |
- //
- // 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");
- }
- }
- }
- #endif
|