コード例 #1
0
ファイル: TableLayoutTest.cs プロジェクト: Profit0004/mono
		public void TestRowColumnSizes11 ()
		{
			// AutoSize Columns/Rows, and column-spanning controls, but
			// no control starts in column 1.
			// Mono's old behavior was for column 1 to have a zero width.
			TableLayoutPanel p = new TableLayoutPanel ();
			Control c1 = new Button ();
			Control c2 = new Button ();
			Control c3 = new Button ();

			c1.Size = new Size (150, 25);
			c2.Size = new Size (75, 25);
			c3.Size = new Size (150, 25);

			p.ColumnCount = 4;
			p.RowCount = 3;

			p.RowStyles.Add (new RowStyle (SizeType.AutoSize));
			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.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));
			p.ColumnStyles.Add (new ColumnStyle (SizeType.AutoSize));

			p.SetColumnSpan (c1, 2);
			p.SetColumnSpan (c3, 2);

			p.Controls.Add (c1, 0, 0);
			p.Controls.Add (c2, 0, 1);
			p.Controls.Add (c3, 1, 1);

			// The bug fix gets Mono to behave very closely to .NET,
			// but not exactly...3 pixels off somewhere...
			Assert.AreEqual (31, p.GetRowHeights ()[0], "D1");
			Assert.AreEqual (31, p.GetRowHeights ()[1], "D2");
			Assert.AreEqual (81, p.GetColumnWidths ()[0], "D3");
			Assert.LessOrEqual (75, p.GetColumnWidths ()[1], "D4");
			Assert.GreaterOrEqual (78, p.GetColumnWidths ()[1], "D5");
			Assert.LessOrEqual (78, p.GetColumnWidths ()[2], "D6");
			Assert.GreaterOrEqual (81, p.GetColumnWidths ()[2], "D7");
		}
コード例 #2
0
ファイル: TableLayoutTest.cs プロジェクト: Profit0004/mono
		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");
		}
コード例 #3
0
ファイル: TableLayoutTest.cs プロジェクト: Profit0004/mono
		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");
		}
コード例 #4
0
ファイル: TableLayoutTest.cs プロジェクト: Profit0004/mono
		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");
		}
コード例 #5
0
ファイル: TableLayoutTest.cs プロジェクト: Profit0004/mono
		public void XamarinBug18638 ()
		{
			// Spanning items should not have their entire width assigned to the first column in the span.
			TableLayoutPanel tlp = new TableLayoutPanel ();
			tlp.SuspendLayout ();
			tlp.Size = new Size(291, 100);
			tlp.AutoSize = true;
			tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 60));
			tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Percent, 100));
			tlp.ColumnStyles.Add (new ColumnStyle (SizeType.Absolute, 45));
			tlp.ColumnCount = 3;
			tlp.RowStyles.Add (new RowStyle (SizeType.AutoSize));
			var label1 = new Label {AutoSize = true, Text = @"This line spans all three columns in the table!"};
			tlp.Controls.Add (label1, 0, 0);
			tlp.SetColumnSpan (label1, 3);
			tlp.RowStyles.Add (new RowStyle (SizeType.AutoSize));
			tlp.RowCount = 1;
			var label2 = new Label {AutoSize = true, Text = @"This line spans columns two and three."};
			tlp.Controls.Add (label2, 1, 1);
			tlp.SetColumnSpan (label2, 2);
			tlp.RowCount = 2;
			AddTableRow (tlp, "First Row", "This is a test");
			AddTableRow (tlp, "Row 2", "This is another test");
			tlp.ResumeLayout ();

			var widths = tlp.GetColumnWidths ();
			Assert.AreEqual (4, tlp.RowCount, "X18638-1");
			Assert.AreEqual (3, tlp.ColumnCount, "X18638-2");
			Assert.AreEqual (60, widths[0], "X18638-3");
			Assert.Greater (label2.Width, widths[1], "X18638-5");
			Assert.AreEqual (45, widths[2], "X18638-4");
		}
コード例 #6
0
ファイル: MainForm.cs プロジェクト: LuckyLuik/AudioVSTToolbox
		Point? GetRowColIndex(TableLayoutPanel tlp, Point point)
		{
			if (point.X > tlp.Width || point.Y > tlp.Height)
				return null;

			int w = tlp.Width;
			int h = tlp.Height;
			int[] widths = tlp.GetColumnWidths();

			int i;
			for (i = widths.Length - 1; i >= 0 && point.X < w; i--)
				w -= widths[i];
			int col = i + 1;

			int[] heights = tlp.GetRowHeights();
			for (i = heights.Length - 1; i >= 0 && point.Y < h; i--)
				h -= heights[i];

			int row = i + 1;

			return new Point(col, row);
		}
コード例 #7
0
ファイル: Form1.cs プロジェクト: CegepGarneau/tache
        //The method to get the position of the cell under the mouse.
        private TableLayoutPanelCellPosition GetCellPosition(TableLayoutPanel panel)
        {
            //mouse position
            System.Drawing.Point p = panel.PointToClient(Control.MousePosition);
            Debug.Assert(p.X >= 0);
            Debug.Assert(p.Y >= 0);
            //Cell position
            TableLayoutPanelCellPosition pos = new TableLayoutPanelCellPosition(0, 0);
            //Panel size.
            Size size = panel.Size;
            //average cell size.
            SizeF cellAutoSize = new SizeF(size.Width / panel.ColumnCount, size.Height / panel.RowCount);

            //Get the cell row.
            //y coordinate
            float y = 0;
            for (int i = 0; i < panel.RowCount; i++)
            {
                //Calculate the summary of the row heights.
                SizeType type = panel.RowStyles[i].SizeType;
                float height = panel.RowStyles[i].Height;
                switch (type)
                {
                    case SizeType.Absolute:
                        y += height;
                        break;
                    case SizeType.Percent:
                        y += height / 100 * size.Height;
                        break;
                    case SizeType.AutoSize:
                        y += cellAutoSize.Height;
                        break;
                }
                //Check the mouse position to decide if the cell is in current row.
                if ((int)y > p.Y)
                {
                    pos.Row = i;
                    break;
                }
            }

            //Get the cell column.
            //x coordinate
            float x = 0;
            for (int i = 0; i < panel.ColumnCount; i++)
            {
                //Calculate the summary of the row widths.
                SizeType type = panel.ColumnStyles[i].SizeType;
                float width = panel.GetColumnWidths()[i];
                switch (type)
                {
                    case SizeType.Absolute:
                        x += width;
                        break;
                    case SizeType.Percent:
                        x += width / 100 * size.Width;
                        break;
                    case SizeType.AutoSize:
                        x += cellAutoSize.Width;
                        break;
                }
                //Check the mouse position to decide if the cell is in current column.
                if ((int)x > p.X)
                {
                    pos.Column = i;
                    break;
                }
            }

            //return the mouse position.
            return pos;
        }
コード例 #8
0
		/// <summary>
		/// Resizes editor controls to fit the last column
		/// </summary>
		/// <param name="tablePanel"></param>
		private static void ResizeEditorControls(TableLayoutPanel tablePanel)
		{
			tablePanel.SuspendLayout();
			try
			{
				// Make editors small
				for (int row = 0; row < tablePanel.RowCount; ++row)
				{
					Control editorControl = tablePanel.GetControlFromPosition(tablePanel.ColumnCount - 1, row);
					Option o = (editorControl != null) ? editorControl.Tag as Option : null;
					if ((o == null) || (editorControl is Label))
					{
						continue;
					}

					// Change
					editorControl.Anchor = AnchorStyles.None;
					editorControl.Width = 5;
				}

				// Layout once
				tablePanel.ResumeLayout(true);
				tablePanel.SuspendLayout();

				// Size now
				int[] colWidths = tablePanel.GetColumnWidths();
				for (int row = 0; row < tablePanel.RowCount; ++row)
				{
					Control editorControl = tablePanel.GetControlFromPosition(tablePanel.ColumnCount - 1, row);
					Option o = (editorControl != null) ? editorControl.Tag as Option : null;
					if ((o == null) || (editorControl is Label))
					{
						continue;
					}

					// Change
					int colWidth = 0;
					for (int col = 0; col < tablePanel.GetColumnSpan(editorControl); col++)
					{
						colWidth += colWidths[colWidths.Length - 1 - col];
					}
					editorControl.Width = colWidth - 10;
					editorControl.Anchor = AnchorStyles.Left | AnchorStyles.Top;
				}
			}
			finally
			{
				tablePanel.ResumeLayout(true);
			}
		}