private void AddPart(AdvancedPart part, int index) { // we're going to be internally consistent layoutParts.SuspendLayout(); Control control; if (part is WinFormsAdvancedPartJunction) { control = new AdvancedPartJunctionView((WinFormsAdvancedPartJunction)part); } else { control = new AdvancedPartNodeView((WinFormsAdvancedPartNode)part); } control.Dock = DockStyle.Fill; layoutParts.RowStyles.Insert(index, new RowStyle(SizeType.AutoSize)); // shift all controls after this point down one row // (the last row will have nothing in it, the row of index will have an existing control for (int i = layoutParts.RowStyles.Count - 2; i >= index; i--) { var move = layoutParts.GetControlFromPosition(0, i); if (move != null) { layoutParts.SetCellPosition(move, new TableLayoutPanelCellPosition(0, i + 1)); } } layoutParts.Controls.Add(control, 0, index); layoutParts.ResumeLayout(); // update height outside SuspendLayout or it won't recalculate correctly //ScrollHeight += ControlHeight(control); }
private void AddPart(AdvancedPart part, int index) { // we're going to be internally consistent layoutParts.SuspendLayout(); Control control; if (part is WinFormsAdvancedPartJunction) control = new AdvancedPartJunctionView((WinFormsAdvancedPartJunction)part); else control = new AdvancedPartNodeView((WinFormsAdvancedPartNode)part); control.Dock = DockStyle.Fill; layoutParts.RowStyles.Insert(index, new RowStyle(SizeType.AutoSize)); // shift all controls after this point down one row // (the last row will have nothing in it, the row of index will have an existing control for (int i = layoutParts.RowStyles.Count - 2; i >= index; i--) { var move = layoutParts.GetControlFromPosition(0, i); if (move != null) layoutParts.SetCellPosition(move, new TableLayoutPanelCellPosition(0, i + 1)); } layoutParts.Controls.Add(control, 0, index); layoutParts.ResumeLayout(); // update height outside SuspendLayout or it won't recalculate correctly //ScrollHeight += ControlHeight(control); }