public int calculate(TableLayoutPanel panel, Label label, Point point, Point loc) { int number = -1; int panelWidth = panel.Width; int panelHeight = panel.Height; int posPanelx1 = panel.Location.X; int posPanely1 = panel.Location.Y; int colWidth = panel.GetColumnWidths()[0]; int rowWidth = panel.GetRowHeights()[0]; int numb = panel.GetColumnWidths().Length; int x = point.X - loc.X - posPanelx1, y = point.Y - loc.Y - posPanely1; if (x >= panelWidth || y >= panelHeight) { Console.WriteLine(">"); return(-1); } number = Convert.ToInt32((y / rowWidth - 1) * numb + x / colWidth); if (number < 0) { number = 0; } return(number); }
protected override void OnMouseDown(MouseEventArgs e) { Capture = true; _lastKnownMousePos = e.Location; if (_vertical) { originalSizes = _viewsGrid.GetColumnWidths(); } else { originalSizes = _viewsGrid.GetRowHeights(); } base.OnMouseDown(e); }
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)); }
//-------------------------------------------------------------------------- // Given a point in a tlp, figure out what cell in that table layout was clicked. //-------------------------------------------------------------------------- TableLayoutPanelCellPosition GetTableLayoutPanelRowColIndexFromPoint(TableLayoutPanel tlp, Point point) { // Adapted from http://stackoverflow.com/questions/15449504/how-do-i-determine-the-cell-being-clicked-on-in-a-tablelayoutpanel if (point.X > tlp.Width || point.Y > tlp.Height) { return(new TableLayoutPanelCellPosition(-1, -1)); } 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 TableLayoutPanelCellPosition(col, row)); }
protected void ScaleToCell(Control control, TableLayoutPanel tableLayoutPanel, string text = null) { var rowHeights = tableLayoutPanel.GetRowHeights(); var columnWidths = tableLayoutPanel.GetColumnWidths(); var position = tableLayoutPanel.GetCellPosition(control); var rectangle = new Rectangle(0, 0, columnWidths[position.Column], rowHeights[position.Row]); rectangle.Width = (int)(rectangle.Width * 0.9f); rectangle.Height = (int)(rectangle.Height * 0.9f); Scale(control, rectangle, text); }
public void TableLayoutPanel_GetColumnWidths_InvokeNoChildren_ReturnsExpected(TableLayoutPanelGrowStyle growStyle) { var control = new Button { Visible = true }; var panel = new TableLayoutPanel { ColumnCount = 3, RowCount = 2, GrowStyle = growStyle }; Assert.Equal(new int[] { 0, 0, 200 }, panel.GetColumnWidths()); }
private static int GetRowWidth([NotNull] TableLayoutPanel tableLayoutPanel) { Assert.ArgumentNotNull(tableLayoutPanel, nameof(tableLayoutPanel)); var rowWidth = 0; int[] columnWidths = tableLayoutPanel.GetColumnWidths(); foreach (int columnWidth in columnWidths) { rowWidth += columnWidth; } return(rowWidth); }
private int GetColumnIndex(TableLayoutPanel tlp, Point point) { if (point.X > tlp.Width || point.Y > tlp.Height) { return(-1); } 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; return(col); }
//Helper Methods public Point GetIndex(TableLayoutPanel t, Point p) { int w = 0, h = 0; int[] widths = t.GetColumnWidths(), heights = t.GetRowHeights(); int i; for (i = 0; i < widths.Length && p.X > w; i++) { w += widths[i]; } int col = i - 1; for (i = 0; i < heights.Length && p.Y + t.VerticalScroll.Value > h; i++) { h += heights[i]; } int row = i - 1; return(new Point(col, row)); }
/// https://stackoverflow.com/questions/15449504/how-do-i-determine-the-cell-being-clicked-on-in-a-tablelayoutpanel /// https://www.codeproject.com/Questions/126882/How-can-I-know-the-clicked-cell-in-the-TableLayout private Point?GetRowColIndex(TableLayoutPanel tlp, int x, int y) { if (x > tlp.Width || y > tlp.Height || x < 0 || y < 0) { return(null); } int[] widths = tlp.GetColumnWidths(); int i = widths.Length - 1; int w = tlp.Width - widths[i]; while (i >= 0 && x < w) { w -= widths[--i]; } int[] heights = tlp.GetRowHeights(); int j = heights.Length - 1; int h = tlp.Height - heights[j]; while (j >= 0 && y < h) { h -= heights[--j]; } return(new Point(i, j)); }
public void TableLayoutPanel_GetColumnWidths_NoColumns_ReturnsExpectd() { var panel = new TableLayoutPanel(); Assert.Empty(panel.GetColumnWidths()); }
public void TabCompAltShow(ref TabPage tab) { tab.Name = curCriteria; tab.Leave += Tab_Leave; tab.AutoScroll = true; tab.Width = tab.Parent.Width; tab.Height = tab.Parent.Height; tboxes = new TextBox[AHP.alternatives_q, AHP.alternatives_q]; tab.Text = String.Format("Критерий \"{0}\"", curCriteria); Label compCrit = new Label(); compCrit.AutoSize = true; compCrit.Text = "Сравнение альтернатив по критерию:\r\n"; compCrit.Font = new Font("Times New Roman", 14.0f, FontStyle.Bold); Label compCrit1 = new Label(); compCrit1.Text = curCriteria; compCrit1.AutoSize = true; compCrit1.Font = new Font("Times New Roman", 16.0f, FontStyle.Bold | FontStyle.Italic | FontStyle.Underline); compCrit1.Location = new Point((tab.Width - compCrit1.Width) / 2, 40); tab.Controls.Add(compCrit); compCrit.Location = new Point((tab.Width - compCrit.Width) / 2, 10); tab.Controls.Add(compCrit1); table = new TableLayoutPanel(); table.Location = new Point(20, 90); table.CellPaint += table_CellPaint; table.ColumnCount = table.RowCount = AHP.alternatives_q + 1; table.AutoSize = true; for (int k = 0; k < AHP.alternatives_q; k++) { string text = AHP.alternatives[k]; /*if (text.Contains(" ")) * { * string[] tmp = text.Split(); * text = ""; * foreach (string v in tmp) * { * if (v.Length == 1) * text += v[0].ToString().ToLower(); * else * text += v[0].ToString().ToUpper(); * } * }*/ table.Controls.Add(new Label { Text = text, Anchor = AnchorStyles.None, AutoSize = true, Font = new Font("Microsoft Sans Serif", 11.0f, FontStyle.Bold) }, 0, k + 1); table.Controls.Add(new Label { Text = text, Anchor = AnchorStyles.None, AutoSize = true, Font = new Font("Microsoft Sans Serif", 11.0f, FontStyle.Bold) }, k + 1, 0); } for (int i = 0; i < table.RowCount; i++) { table.RowStyles.Add(new RowStyle() { Height = 30, SizeType = SizeType.Percent }); table.ColumnStyles.Add(new ColumnStyle() { SizeType = SizeType.Percent }); } for (int i = 1; i < table.RowCount; i++) { for (int j = 1; j < table.ColumnCount; j++) { int tI = i - 1; int tJ = j - 1; tboxes[tJ, tI] = new TextBox(); tboxes[tJ, tI].TextAlign = HorizontalAlignment.Center; tboxes[tJ, tI].MaxLength = 15; tboxes[tJ, tI].Anchor = AnchorStyles.None; tboxes[tJ, tI].Margin = new Padding(1, 1, 1, 1); tboxes[tJ, tI].BorderStyle = BorderStyle.None; tboxes[tJ, tI].Name = tJ.ToString() + "-" + tI.ToString(); tboxes[tJ, tI].Font = new Font("Microsoft Sans Serif", 12.0f); if (tI == tJ) { tboxes[tJ, tI].Text = "1"; tboxes[tJ, tI].ReadOnly = true; tboxes[tJ, tI].TabStop = false; tboxes[tJ, tI].BorderStyle = BorderStyle.None; } tboxes[tJ, tI].TextChanged += Ont_text_changed; table.Controls.Add(tboxes[tJ, tI], j, i); } } int tWidth = 0; for (int i = 1; i < table.RowCount; i++) { int w = table.GetColumnWidths()[i]; if (w > tWidth) { tWidth = w; } } foreach (TextBox tb in tboxes) { tb.Width = tWidth; } tab.Controls.Add(table); if (table.Width > tab.Width) { table.Location = new Point(20, table.Location.Y); } else { table.Location = new Point((tab.Width - table.Width) / 2, table.Location.Y); } SetDoubleBuffered(table); foreach (Control c in table.Controls) { SetDoubleBuffered(c); } Button button = new Button(); button.Text = "Далее"; button.Size = new Size(100, 50); button.Location = new Point((tab.Width - button.Width) / 2, table.Location.Y + table.Height + 40); button.Font = new Font("Microsoft Sans Serif", 12.0f); button.Click += new System.EventHandler(this.btnCompAlt_Click); tab.Controls.Add(button); }