public ControlGroup this[int index] { get { ControlGroup ctrlGroup = (ControlGroup)Table.GetControlFromPosition(0, index); if (ctrlGroup == null) { ctrlGroup = (ControlGroup)Table.Controls[index]; if (Table.GetRow(ctrlGroup) != index) { foreach (Control c in Table.Controls) { if (Table.GetRow(c) == index) { ctrlGroup = (ControlGroup)c; break; } } } } return(ctrlGroup); } set { Insert(index, value); } }
public static void RemoveRow(this TableLayoutPanel tableLayoutPanel, int rowNumber) { ArrayList controls = new ArrayList(tableLayoutPanel.Controls); foreach (Control control in controls) { int row = tableLayoutPanel.GetRow(control); if (row == rowNumber) { tableLayoutPanel.Controls.Remove(control); } } tableLayoutPanel.RowStyles.RemoveAt(rowNumber); foreach (Control control in tableLayoutPanel.Controls) { int row = tableLayoutPanel.GetRow(control); if (row > rowNumber) { tableLayoutPanel.SetRow(control, row - 1); } } tableLayoutPanel.PerformLayout(); tableLayoutPanel.ResumeLayout(true); tableLayoutPanel.Refresh(); }
public void TableLayoutPanel_SetRow_MultipleTimes_GetReturnsExpected() { var control = new ScrollableControl(); var panel = new TableLayoutPanel(); panel.SetRow(control, 1); Assert.Equal(1, panel.GetRow(control)); panel.SetRow(control, 2); Assert.Equal(2, panel.GetRow(control)); }
public void MoveControlsUpN(TableLayoutPanel table, int startID, int N) { int rowCount = table.RowStyles.Count; foreach (Control c in table.Controls) { if (table.GetRow(c) > startID) { table.SetRow(c, table.GetRow(c) - N); } } }
public void Verificar_CartaClicada(Form frm, TableLayoutPanel tlp, ref int r, ref int c, ref string nome_obj, PictureBox carta_clicada, ref bool aux) { if (carta_clicada != null) { r = tlp.GetRow(carta_clicada); c = tlp.GetColumn(carta_clicada); nome_obj = matObj[r, c].nome; if (carta_clicada.Image == carta_clicada.Tag) { return; } if (clique1 == null) { clique1 = carta_clicada; clique1.Image = (Image)carta_clicada.Tag; return; } if (clique2 == null) { clique2 = carta_clicada; clique2.Image = (Image)carta_clicada.Tag; aux = true; tentativas++; } /*if (Comparar_Imagens((Bitmap)clique1.Image, (Bitmap)clique2.Image)) * { * clique1 = null; * clique2 = null; * * aux = false; * * return; * }*/ if (matObj[tlp.GetRow(clique1), tlp.GetColumn(clique1)].ID == matObj[tlp.GetRow(clique2), tlp.GetColumn(clique2)].ID) { clique1 = null; clique2 = null; aux = false; return; } } }
} //Adds ComboBox to cell private void UpdateItems(Object sender, EventArgs e) { ComboBox cb = (ComboBox)sender; //Case object to ComboBox int r = p.GetRow(cb); int c = p.GetColumn(cb); try { puzzle[r, c] = (int)cb.SelectedIndex;//Places changed value into indexed array }catch (InvalidCastException ex) { Console.WriteLine(ex); } } //Updates array when ComboBox value is changed
private static void SetRowValue(TableLayoutPanel layoutPanel, Control label, string value) { if (!String.IsNullOrEmpty(value)) { label.Text = value; layoutPanel.RowStyles[layoutPanel.GetRow(label)].SizeType = SizeType.AutoSize; } else { layoutPanel.RowStyles[layoutPanel.GetRow(label)].SizeType = SizeType.Absolute; layoutPanel.RowStyles[layoutPanel.GetRow(label)].Height = 0; } layoutPanel.AutoScroll = true; }
/// <summary> /// 统计标签高度 /// </summary> public void countLabelHeight() { //计算标签高度 processLabelHeight(Text); try { //设置TableLayout布局,用于解决在某些状态下由于自动计算高度导致的遮蔽了下面的控件的BUG //查找TableLayoutPanel TableLayoutPanel panel = GetLayoutPanel(); if (panel != null) { //本控件在TableLayoutPanel中是第几行 int tableLayoutRow = -1; if (panel != this.Parent) { //Label上面还有一级 tableLayoutRow = panel.GetRow(this.Parent); } else { //Label上面直接就是TableLayoutPanel tableLayoutRow = panel.GetRow(this); } if (tableLayoutRow >= 0) { if (AutoHeight) { panel.SuspendLayout(); panel.RowStyles[tableLayoutRow].SizeType = SizeType.Absolute; if (Height > panel.RowStyles[tableLayoutRow].Height) { panel.RowStyles[tableLayoutRow].Height = Height; } panel.ResumeLayout(false); } else { panel.RowStyles[tableLayoutRow].SizeType = SizeType.AutoSize; } } } } catch (Exception ex) { } }
private static void MoveRowsDown(TableLayoutPanel panel) { var addRemoveBtns = panel.Controls.Cast <Control>() .Where(c => panel.GetRow(c) == panel.RowCount - 2); addRemoveBtns.ForEach(i => panel.SetRow(i, panel.RowCount - 1)); }
public void TableLayoutPanel_GetRow_NoSuchControl_ReturnsExpected() { var control = new ScrollableControl(); var panel = new TableLayoutPanel(); Assert.Equal(-1, panel.GetRow(control)); }
public int PrepareForNextRound(TableLayoutPanel table, GameEngine game, Label cell) { game.ChosenCategory(table.GetRow(cell)); cell.Text = game.Score.ToString(); // tymczasowo, potem będą tutaj wzorki potworki return(game.TotalScore); }
void PopUpControl_CloseUp(object sender, CloseUpEventArgs e) { var popUpContainerEdit = sender as PopupContainerEdit; if (popUpContainerEdit != null) { const int extraSize = 51; int newSize = popUpContainerEdit.Size.Height + popUpContainerEdit.Properties.PopupControl.Size.Height + extraSize; if (popUpContainerEdit.Parent != null) { int rowIndex = _table.GetRow(popUpContainerEdit.Parent); _table.RowStyles[rowIndex].SizeType = SizeType.Absolute; _table.RowStyles[rowIndex].Height = extraSize; } } }
public void TableLayoutPanel_SetRow_ValidControl_GetReturnsExpected(int value) { var control = new ScrollableControl(); var panel = new TableLayoutPanel(); panel.SetRow(control, value); Assert.Equal(value, panel.GetRow(control)); }
/// <summary> /// Popups the event handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="eventArgs">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void PopupEventHandler(object sender, EventArgs eventArgs) { var popContainerEdit = sender as PopupContainerEdit; _table.SuspendLayout(); if (popContainerEdit != null) { const int extraHeight = 40; var newSize = popContainerEdit.Properties.PopupControl.Size.Height + popContainerEdit.Size.Height + extraHeight; var rowIndex = _table.GetRow(popContainerEdit.Parent); _table.RowStyles[rowIndex].SizeType = SizeType.Absolute; _table.RowStyles[rowIndex].Height = newSize; } _table.ResumeLayout(); }
public int PrepareForNextRound(TableLayoutPanel table, Engine game, Label cell) { game.ChosenCategory(table.GetRow(cell)); cell.Text = game.Score.ToString(); return(game.TotalScore); }
private Control GetClickedRuleElement(object sender) { ToolStripMenuItem menuItem = sender as ToolStripMenuItem; ContextMenuStrip contextMenu = menuItem.Owner as ContextMenuStrip; int row = tableLayoutPanel.GetRow(contextMenu.SourceControl); return(tableLayoutPanel.GetControlFromPosition(0, row)); }
/// <summary> /// Clears a row off a <see cref="TableLayoutPanel"/>, based on a <see cref="Control"/>. /// The row index is retrieved via the passed control. /// </summary> /// <param name="tableLayoutPanel"><see cref="TableLayoutPanel"/></param> /// <param name="control"><see cref="Control"/></param> public static void DeleteTableRow(TableLayoutPanel tableLayoutPanel, Control control) { int row = tableLayoutPanel.GetRow(control); for (int col = 0; col < tableLayoutPanel.ColumnCount; col++) { tableLayoutPanel.Controls.Remove(tableLayoutPanel.GetControlFromPosition(col, row)); } tableLayoutPanel.RowCount--; }
public static void HideRows(this TableLayoutPanel panel, params int[] rowNumbers) { foreach (Control c in panel.Controls) { if (rowNumbers.Contains(panel.GetRow(c))) { c.Visible = false; } } }
/// <summary> /// TableLayoutPanel において、実際に利用されている行数を取得します。 /// デフォルトの RowCount 及び RowStyles.Count は実際と異なる値を返すことがあるためです。 /// </summary> public static int GetActualRowCount(TableLayoutPanel panel) { int count = panel.RowCount; foreach (System.Windows.Forms.Control c in panel.Controls) { count = Math.Max(panel.GetRow(c) + 1, count); } return(count); }
public void TableLayoutControlCollection_Add_NegativeColumn_ThrowsArgumentOutOfRangeException() { using var container = new TableLayoutPanel(); var collection = new TableLayoutControlCollection(container); using var child = new Control(); Assert.Throws <ArgumentOutOfRangeException>("column", () => collection.Add(child, -2, 2)); Assert.Equal(child, Assert.Single(collection)); Assert.Equal(-1, container.GetColumn(child)); Assert.Equal(-1, container.GetRow(child)); }
public void TableLayoutControlCollection_Add_NegativeRow_ThrowsArgumentOutOfRangeException() { var container = new TableLayoutPanel(); var collection = new TableLayoutControlCollection(container); var control = new Control(); Assert.Throws <ArgumentOutOfRangeException>("row", () => collection.Add(control, 1, -2)); Assert.Equal(control, Assert.Single(collection)); Assert.Equal(1, container.GetColumn(control)); Assert.Equal(-1, container.GetRow(control)); }
public void TableLayoutControlCollection_Add_ValidControl_Success(int column, int row) { var container = new TableLayoutPanel(); var collection = new TableLayoutControlCollection(container); var control = new Control(); collection.Add(control, column, row); Assert.Equal(control, Assert.Single(collection)); Assert.Equal(column, container.GetColumn(control)); Assert.Equal(row, container.GetRow(control)); }
public static void RemoveItem(TableLayoutPanel tlp, Control control) { int Position = tlp.GetRow(control); if (Position < tlp.RowCount - 1) { for (int i = Position; i < tlp.RowCount - 1; i++) { tlp.SetRow(tlp.GetControlFromPosition(0, i + 1), i); } } tlp.RowCount -= 1; }
public static IEnumerable <Control> GetControlsFromRow(this TableLayoutPanel panel, int row) { var retVal = new List <Control>(); foreach (Control item in panel.Controls) { if (panel.GetRow(item) == row) { retVal.Add(item); } } return(retVal); }
private IList <int> GetInvisibleRowsWithControl(TableLayoutPanel panel) { List <int> list = new List <int>(); foreach (object obj in panel.Controls) { Control control = (Control)obj; int row = panel.GetRow(control); if (row >= 0 && !list.Contains(row)) { list.Add(row); } } foreach (object obj2 in panel.Controls) { Control control2 = (Control)obj2; if (this.GetControlVisible(control2)) { list.Remove(panel.GetRow(control2)); } } return(list); }
private void Text_Score_Leave(object sender, EventArgs e) { TextBox txtBx = (TextBox)sender; string[] text = txtBx.Text.Split(':'); if (txtBx.Text.Length != 3 || text.Length != 2) { txtBx.Text = ""; } TableLayoutPanel tableLayout = (TableLayoutPanel)txtBx.Parent; int row_number = tableLayout.GetRow(txtBx); SetScoreMatch(row_number, txtBx); }
private int GetIndexFromTextBox(TextBox tBox) { int row = 0; int num = 0; foreach (Control control in (ArrangedElementCollection)panel.Controls) { if (control is TextBox && control == tBox) { num = panel.GetColumn(control); row = panel.GetRow(control); break; } } return(registers.IndexOf(registers[panel.GetControlFromPosition(num - 2, row).Text])); }
//public class Border //{ // public TableLayoutPanelCellBorderStyle style = TableLayoutPanelCellBorderStyle.Single; //} public void apply(TableLayoutPanel table) { //int rowsCount = table.RowCount; //int ColumnCount = table.ColumnCount; foreach (Control control in table.Controls) { if (table.GetRow(control) == 0) { RowHeader.apply(control); } else if (table.GetColumn(control) == 0) { ColumnHeader.apply(control); } } }
private int GetIndexFromTextBox(TextBox tBox) { int row = 0; int column = 0; foreach (Control control in panel.Controls) { if ((control is TextBox) && (control == tBox)) { column = panel.GetColumn(control); row = panel.GetRow(control); break; } } Label controlFromPosition = (Label)panel.GetControlFromPosition(column - 2, row); return(registers.IndexOf(registers[controlFromPosition.Text])); }
private AlignUnitsCollection(TableLayoutPanel panel) { IDictionary <int, int> rowsMapping = this.GetRowsMapping(panel); this.unitsCollection = new AlignUnit[rowsMapping.Count, panel.ColumnCount]; this.RowDeltaValue = new int[rowsMapping.Count]; foreach (object obj in panel.Controls) { Control control = (Control)obj; int row = panel.GetRow(control); int column = panel.GetColumn(control); if (this.GetControlVisible(control) && row >= 0 && column >= 0) { int num = rowsMapping[row]; int num2 = column; AlignUnit alignUnit = new AlignUnit(control, panel.GetRowSpan(control), panel.GetColumnSpan(control), num, num2); for (int i = 0; i < alignUnit.ColumnSpan; i++) { this.unitsCollection[num, num2 + i] = alignUnit; } this.unitsList.Add(alignUnit); if (!this.rowUnitsDictionary.ContainsKey(num)) { this.rowUnitsDictionary[num] = new List <AlignUnit>(); } this.rowUnitsDictionary[num].Add(alignUnit); } } for (int j = 0; j < this.RowCount; j++) { if (!this.rowUnitsDictionary.ContainsKey(j)) { this.rowUnitsDictionary[j] = new List <AlignUnit>(); } else { this.rowUnitsDictionary[j].Sort(); } this.RowDeltaValue[j] = AlignSettings.DefaultVertical; } this.UpdateCompareMargin(); }