/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.SizeControl(Size)"/> protected override void SizeControl(Size parentsize) { base.SizeControl(parentsize); if (AutoSize) { GLMenuStrip p = Parent as GLMenuStrip; ButtonAutoSize(p != null ? new Size(p.IconAreaWidth, 0) : Size.Empty); } }
/// <summary> Find top level menu of this tree </summary> public GLMenuStrip GetTopLevelMenu() { GLMenuStrip m = this; while (m.parentmenu != null) { m = m.parentmenu; } return(m); }
/// <summary> /// Select an item at index /// </summary> /// <param name="index">Index of item</param> /// <param name="focusto">If true, change focus to item</param> /// <returns>true if changed to item</returns> public bool Select(int index, bool focusto) { if (submenu != null) // if submenu is activated.. { if (index == selected) // if already selected, its open { return(true); } CloseSubMenus(); // close any current ones } if (index >= 0 && index < ControlsIZ.Count) { var mi = ControlsIZ[index] as GLMenuItem; //System.Diagnostics.Debug.WriteLine("Selected " + index + " in " + Name); if (mi != null && mi.SubMenuItems != null) // actually a submenu.. { Point offset; if (FlowDirection == ControlFlowDirection.Right) // pick co-ords based on flow { offset = new Point(mi.Left - this.ClientLeftMargin, this.Height); } else { offset = new Point(Width, mi.Top); } Point p = FindScreenCoords(offset); // find this point in bounds on screen submenu = new GLMenuStrip(Name + "." + mi.Name, new Rectangle(p.X, p.Y, 200, 200)); // size is immaterial , autosize both submenu.ScaleWindow = FindScaler(); //System.Diagnostics.Debug.WriteLine("Open menu " + submenu.Name + " " + submenu.Bounds); submenu.Font = Font; submenu.BackColor = this.BackColor; submenu.BackColorGradientAlt = this.BackColorGradientAlt; submenu.BackColorGradientDir = this.BackColorGradientDir; submenu.IconStripBackColor = this.IconStripBackColor; submenu.FlowDirection = ControlFlowDirection.Down; submenu.AutoSize = true; submenu.AutoOpenDelay = AutoOpenDelay; submenu.parentmenu = this; submenu.TopMost = true; submenu.BorderWidth = SubMenuBorderWidth; submenu.SubMenuBorderWidth = SubMenuBorderWidth; submenu.AddItems(mi.SubMenuItems); submenu.SetSelected(-1); // release all items for hover highlighting AddToDesktop(submenu); SetSelected(index); // set selected thus fixing highlight on this one GetTopLevelMenu().SubmenuOpened?.Invoke(mi, submenu); // call, allowing configuration of the submenu if (focusto) // used to transfer focus to submenu. Note submenu with focus has up/down keys { submenu.SetFocus(); } else { SetFocus(); // else ensure we have the focus, in case due to keyboard hit } return(true); } else { SetSelected(index); // not a menu or other, select it if (mi == null) { ControlsIZ[index].SetFocus(); // not a menu item, it gets focus. } return(true); } } else { return(false); } }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.Paint(Graphics)"/> protected override void Paint(Graphics gr) { Rectangle butarea = ClientRectangle; GLMenuStrip p = Parent as GLMenuStrip; bool ica = IconAreaEnable && p != null; if (ica) { butarea.Width -= p.IconAreaWidth; butarea.X += p.IconAreaWidth; } if (Enabled && (Highlighted || (Hover && !DisableHoverHighlight))) { base.PaintButtonFace(ClientRectangle, gr, MouseOverColor); } else { if (ica) { using (Brush br = new SolidBrush(p.IconStripBackColor)) { gr.FillRectangle(br, new Rectangle(0, 0, p.IconAreaWidth, ClientHeight)); } } base.PaintButtonFace(butarea, gr, Enabled ? ButtonFaceColour : ButtonFaceColour.Multiply(BackDisabledScaling)); } //using (Brush inner = new SolidBrush(Color.Red)) gr.FillRectangle(inner, butarea); // Debug base.PaintButtonTextImageFocus(butarea, gr, false); // don't paint the image if (ica) { int reduce = (int)(p.IconAreaWidth * TickBoxReductionRatio); Rectangle tickarea = new Rectangle((p.IconAreaWidth - reduce) / 2, (ClientHeight - reduce) / 2, reduce, reduce); if (CheckState != CheckStateType.Unchecked) { float discaling = Enabled ? 1.0f : BackDisabledScaling; Color checkboxbordercolour = CheckBoxBorderColor.Multiply(discaling); //(Enabled && Hover) ? MouseOverBackColor : Color backcolour = (Enabled && Hover) ? MouseOverColor : ButtonFaceColour.Multiply(discaling); using (Brush inner = new System.Drawing.Drawing2D.LinearGradientBrush(tickarea, CheckBoxInnerColor.Multiply(discaling), backcolour, 225)) gr.FillRectangle(inner, tickarea); // fill slightly over size to make sure all pixels are painted using (Pen outer = new Pen(checkboxbordercolour)) // paint over to ensure good boundary gr.DrawRectangle(outer, tickarea); } tickarea.Inflate(-1, -1); // reduce it around the drawn box above if (Image != null) // if we have an image, draw it into the tick area { base.DrawImage(Image, tickarea, gr, (Enabled) ? drawnImageAttributesEnabled : drawnImageAttributesDisabled); } else { base.DrawTick(tickarea, Color.FromArgb(200, CheckColor.Multiply(Enabled ? 1.0F : ForeDisabledScaling)), CheckState, gr); } } }