/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.SizeControl(Size)"/> protected override void SizeControl(Size parentsize) { if (ControlsIZ.Count > 0 && Parent != null) // if not resizable, and we have stuff { if (AutoSize && !Resizeable) // if autosizable, and not resizable (turned off and on AFTER added into the display control etc) we can set the size { //System.Diagnostics.Debug.WriteLine($"conf {Name} Attempt resize"); base.SizeControl(parentsize); // first perform the Form Autosize - taking into consideration title and objects other than the autoplacement items Rectangle area = VisibleChildArea(x => (x.Anchor & AnchorType.AutoPlacement) == 0); // get the clients area , ignoring anchor buttons int buttonsmaxh = ControlsIZ.Where(x => (x.Anchor & AnchorType.AutoPlacement) != 0).Select(x => x.Height + AnchorDialogButtonLineSpacing).DefaultIfEmpty(0).Max() + AutoSizeClientMargin.Height; int buttonswidth = ControlsIZ.Where(x => (x.Anchor & AnchorType.AutoPlacement) != 0).Select(y => y.Width + AnchorDialogButtonLineSpacing).DefaultIfEmpty(0).Sum() + AutoSizeClientMargin.Width; if (ClientWidth < buttonswidth || ClientHeight < area.Top + area.Height + buttonsmaxh) { //System.Diagnostics.Debug.WriteLine($"Conf {Name} Need to make it wider/height for buttons {buttonswidth} {buttonsmaxh} "); Size news = new Size(Math.Max(ClientWidth, buttonswidth), Math.Max(ClientHeight, area.Top + area.Height + buttonsmaxh)); SetNI(clientsize: news); if (SetMinimumSizeOnAutoSize) { MinimumSize = Size; } } } if (!Moveable) // as long as not movable (turned on AFTER added into the display control etc) we can set the position { Size psize = Parent.Size; if (centred) { int left = psize.Width / 2 - Size.Width / 2; int top = psize.Height / 2 - Size.Height / 2; SetNI(location: new Point(left, top)); } else { int left = location.X; if (left + Width > psize.Width) { left = psize.Width - Width; } int top = location.Y; if (top + Height > psize.Height) { top = psize.Height - Height; } SetNI(location: new Point(left, top)); } } } }
private void MenuItemEnter(object c, GLMouseEventArgs e) { GLBaseControl b = c as GLBaseControl; mousehovered = ControlsIZ.IndexOf(b); // when we move the mouse, the selected is discarded, and mousehover takes over SetSelected(-1); GLMenuItem mi = ControlsIZ[mousehovered] as GLMenuItem; // if its a menu item, lets do a timer to autoopen if (mi != null && AutoOpenDelay > 0) { timer.Start(AutoOpenDelay); } }
private void MenuItemClicked(GLBaseControl c) { System.Diagnostics.Debug.Assert(Parent != null); // double check we are not on a zombie control, due to the add/remove stuff var mi = c as GLMenuItem; if (mi != null) // menu items are handled by us { if (mi.SubMenuItems != null) { Select(ControlsIZ.IndexOf(mi), FlowDirection == ControlFlowDirection.Right); } else { GetTopLevelMenu().CloseMenus(); } } }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.PerformRecursiveLayout"/> protected override void PerformRecursiveLayout() { base.PerformRecursiveLayout(); // do normal layout on children int buttonsmaxh = ControlsIZ.Where(x => (x.Anchor & AnchorType.AutoPlacement) != 0).Select(x => x.Height).DefaultIfEmpty(0).Max(); int buttonline = ClientHeight - AutoSizeClientMargin.Height - buttonsmaxh; int buttonright = ClientWidth - AutoSizeClientMargin.Width; foreach (var control in ControlsIZ) { if ((control.Anchor & AnchorType.AutoPlacement) != 0) // if dialog line anchor { buttonright -= control.Width; var pos = new Point(buttonright, buttonline); //System.Diagnostics.Debug.WriteLine($"{control.Name} {control.Size} to {pos}"); control.SetNI(location: pos); buttonright -= AnchorDialogButtonLineSpacing; } } }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.Paint(Graphics)"/> protected override void Paint(Graphics gr) { // called after the background of the panel has been drawn - so it will be clear to write. int i = 0; foreach (var c in ControlsIZ.OfType <GLTabPage>()) // draw all but selected { if (i != seltab) { DrawTab(gr, new Rectangle(tabrectangles[i].Left, tabrectangles[i].Top, tabrectangles[i].Width, tabrectangles[i].Height), c.Text, null, false, mouseover == i); } i++; } if (seltab >= 0 && seltab < ControlsIZ.Count) // and draw selected { var c = ControlsIZ[seltab] as GLTabPage; DrawTab(gr, new Rectangle(tabrectangles[seltab].Left, tabrectangles[seltab].Top, tabrectangles[seltab].Width, tabrectangles[seltab].Height), c.Text, null, true, mouseover == seltab); } }