int groupCount = 0; // global integer used by process group in the case that a block does not have a name or caption. #endregion /// <summary> /// Creates a new Tab page in the tab control. /// </summary> private void CreateTab(string caption) { TabItem item = tabControl.CreateTab(caption); tabControl.Margin = new Padding(0); isLoaded.Add(false); ThemedPanel intermediatePanel = new ThemedPanel(); intermediatePanel.Dock = DockStyle.Fill; intermediatePanel.AutoScroll = true; intermediatePanel.Margin = new Padding(0); item.AttachedControl.Controls.Add(intermediatePanel); intermediatePanel.Scroll += new ScrollEventHandler(intermediatePanel_Scroll); intermediatePanel.SizeChanged += new EventHandler(intermediatePanel_SizeChanged); FieldContainerPanel panel = new FieldContainerPanel(); panel.AutoSize = true; panel.AutoSizeMode = Prometheus.Controls.TagEditor.AutoSizeType.GrowAndShrink | Prometheus.Controls.TagEditor.AutoSizeType.WidthAndHeight; panel.Location = new Point(0, 0); panel.Margin = new Padding(0, 0, 0, 0); panel.Name = "TagEditorTab"; intermediatePanel.Controls.Add(panel); containers.Push(panel); }
private static void AutoSizePanel(ref bool dirty, FieldContainerPanel panel, ref int maxWidth, ref System.Drawing.Point lastLocation) { if ((panel.AutoSizeMode & AutoSizeType.Height) == AutoSizeType.Height) { int newHeight = lastLocation.Y + panel.Margin.Bottom; if (newHeight > panel.Height) { if (FlagIsSet(panel.AutoSizeMode, AutoSizeType.Grow)) { panel.Height = newHeight; dirty = true; } } else if (newHeight < panel.Height) { if (FlagIsSet(panel.AutoSizeMode, AutoSizeType.Shrink)) { panel.Height = newHeight; dirty = true; } } } if ((panel.AutoSizeMode & AutoSizeType.Width) == AutoSizeType.Width) { maxWidth += panel.Margin.Right; if (maxWidth > panel.Width) { if (FlagIsSet(panel.AutoSizeMode, AutoSizeType.Grow)) { panel.Width = maxWidth; dirty = true; } } else if (maxWidth < panel.Width) { if (FlagIsSet(panel.AutoSizeMode, AutoSizeType.Shrink)) { panel.Width = maxWidth; dirty = true; } } } //if (panel.Parent != null) //{ //if (panel.Location.X + panel.Width > panel.Parent.Width) //panel.Width = panel.Parent.Width - panel.Location.X - 1; //} }
public override bool Layout(object container, LayoutEventArgs layoutEventArgs) { bool dirty = false; if (container is FieldContainerPanel) { FieldContainerPanel panel = container as FieldContainerPanel; int minimumWidth = (BlockWidth + (panel.DepthDifference * (panel.Margin.Left * 2))) - 1; if (panel.Width < minimumWidth) { panel.Width = minimumWidth; dirty = true; } //panel.SuspendLayout(); bool controlFound = (layoutEventArgs.AffectedControl == panel); int maxWidth = 0; System.Drawing.Point lastLocation = new Point(); lastLocation = new System.Drawing.Point(panel.Margin.Left, panel.Margin.Top); bool inGroup = false; int groupCount = 0; // to prevent spacing of groups that don't have enough controls. for (int x = 0; x < panel.Controls.Count; x++) { if (!controlFound) { if (panel.Controls[x] == layoutEventArgs.AffectedControl) { controlFound = true; } } Point newLocation = lastLocation; // List's go from top to bottom, thus, we don't need to do any layout until we get to the control that's changed. if (controlFound) { if (panel.DrawBorder) { // if the current control is a field container... if (panel.Controls[x] is IFieldControl) { newLocation = new Point(lastLocation.X + panel.Margin.Left, lastLocation.Y + panel.Padding.Top); inGroup = true; groupCount++; } else { if ((inGroup) && (groupCount >= MinimumGroupCount)) { // put in some extra padding between groups. newLocation = new System.Drawing.Point(lastLocation.X, lastLocation.Y + 1); } else { newLocation = new System.Drawing.Point(lastLocation.X, lastLocation.Y); } inGroup = false; groupCount = 0; } } if (panel.Controls[x].Location != newLocation) { panel.Controls[x].Location = newLocation; dirty = true; } if (panel.Controls[x] is FieldContainerBase) { FieldContainerBase tempContainer = panel.Controls[x] as FieldContainerBase; bool isSuspended = tempContainer.LayoutSuspended; int newContainerWidth = 0; if (tempContainer.FieldPanel != null) { if (tempContainer.FieldPanel.DepthDifference > -1) { newContainerWidth = (BlockWidth + (tempContainer.FieldPanel.DepthDifference * (tempContainer.Location.X * 2))) - 1; } } else if (tempContainer.Globals.DepthDifference > -1) { newContainerWidth = (BlockWidth + (tempContainer.Globals.DepthDifference * (tempContainer.Location.X * 2))) - 1; } if (newContainerWidth != 0) { if (newContainerWidth != tempContainer.Width) { tempContainer.Width = newContainerWidth; dirty = true; } } if (tempContainer.Block != null) { (tempContainer.Block as Control).Width = tempContainer.Width - 2; } } else if (panel.Controls[x] is IFieldControl) { // Center the controls for Nick. This may need to be replaced if we ever desire the use of margins. panel.Controls[x].Width = panel.Width - (panel.Controls[x].Location.X * 2); } } lastLocation = new System.Drawing.Point(panel.Margin.Left, panel.Controls[x].Location.Y + panel.Controls[x].Height + panel.Padding.Top); if (panel.Controls[x] is BlockContainerPanel) { if (panel.Controls[x].Width > maxWidth) { maxWidth = panel.Controls[x].Width; } } else if (panel.Controls[x].Location.X + panel.Controls[x].Width + panel.Padding.Right > maxWidth) { maxWidth = panel.Controls[x].Location.X + panel.Controls[x].Width + panel.Padding.Right; } } #region Autosize the panel. if (panel.AutoSize == true) { AutoSizePanel(ref dirty, panel, ref maxWidth, ref lastLocation); } #endregion if (!(panel.Parent is BlockContainer)) { if (panel.Width < minimumWidth) { panel.Width = minimumWidth + 1; dirty = true; } } // Group controls... if (panel.DrawBorder) { groups = GroupControls(typeof(IFieldControl), panel.Controls); } else { groups = null; } //panel.Location = new Point(0, panel.Location.Y); //if (dirty) // panel.Invalidate(false); return(true); } return(false); }