// no cursor.. // Since splitter is used as the primary history window, we need to be more careful due to this being used as the primary cursor // so we by design don't have a cursor at Init on any UCCB. So we must create everything here for the primary, then we have a cursor, and // then load layout can finish the job public override void Init() { TabListSortAlpha = EDDConfig.Instance.SortPanelsByName; // held constant, because we store in each tab splitter the implicit order, can't change it half way thru string defaultview = "H(0.50, U'0,-1', U'1,-1')"; // default is a splitter without any selected panels string splitctrl = SQLiteConnectionUser.GetSettingString(DbWindows, defaultview); SuspendLayout(); //try and make the configured splitter tree SplitContainer sp = ControlHelpersStaticFunc.SplitterTreeMakeFromCtrlString(new BaseUtils.StringParser(splitctrl), MakeSplitContainer, MakeNode, 0); if (sp == null) // string is screwed, nothing was returned. Lets set the default up { sp = ControlHelpersStaticFunc.SplitterTreeMakeFromCtrlString(new BaseUtils.StringParser(defaultview), MakeSplitContainer, MakeNode, 0); } panelPlayfield.Controls.Add(sp); ResumeLayout(); BaseUtils.Translator.Instance.Translate(contextMenuStripSplitter, this); RunActionOnSplitterTree((p, c, uccb) => { int tagid = (int)c.Tag; int displaynumber = DisplayNumberOfSplitter(tagid); // tab strip - use tag to remember display id which helps us save context. System.Diagnostics.Trace.WriteLine("SP:Make UCCB " + uccb.GetType().Name + " tag " + tagid + " dno " + displaynumber); uccb.Init(discoveryform, displaynumber); }); // contract states the PanelAndPopOuts OR the MajorTabControl will now theme and size it. }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.DrawBorder(Graphics, Color, float)"/> protected override void DrawBorder(Graphics gr, Color bc, float bw) { base.DrawBorder(gr, bc, bw); // draw basic border Color c = (Enabled) ? this.ForeColor : this.ForeColor.Multiply(ForeDisabledScaling); if (Text.HasChars()) { using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(TextAlign)) { using (Brush textb = new SolidBrush(c)) { Rectangle titlearea = new Rectangle(0, 0, Width - (ShowClose?TitleBarHeight:0), TitleBarHeight); gr.DrawString(this.Text, this.Font, textb, titlearea, fmt); } } } if (ShowClose) { Rectangle closearea = new Rectangle(Width - TitleBarHeight, 0, TitleBarHeight, TitleBarHeight); closearea.Inflate(new Size(-6, -6)); using (Pen p = new Pen(c)) { gr.DrawLine(p, new Point(closearea.Left, closearea.Top), new Point(closearea.Right, closearea.Bottom)); gr.DrawLine(p, new Point(closearea.Left, closearea.Bottom), new Point(closearea.Right, closearea.Top)); } } }
public override void Closing() { PanelInformation.PanelIDs[] pids = PanelInformation.GetPanelIDs(); string state = ControlHelpersStaticFunc.SplitterTreeState(panelPlayfield.Controls[0] as SplitContainer, "", (c) => // S is either a TabStrip, or a direct UCCB. See the { ExtendedControls.TabStrip ts = c as ExtendedControls.TabStrip; int tagid = (int)c.Tag; if (ts != null) // if tab strip.. { return(tagid.ToStringInvariant() + "," + (ts.SelectedIndex >= 0 ? (int)pids[ts.SelectedIndex] : NoTabPanelSelected).ToStringInvariant()); } else { PanelInformation.PanelInfo pi = PanelInformation.GetPanelInfoByType(c.GetType()); // must return, as it must be one of the UCCB types return(tagid.ToStringInvariant() + "," + (FixedPanelOffset + ((int)pi.PopoutID)).ToStringInvariant()); } }); //System.Diagnostics.Debug.WriteLine("Split save " + state); SQLiteConnectionUser.PutSettingString(DbWindows, state); (panelPlayfield.Controls[0] as SplitContainer).RunActionOnSplitterTree((p, c) => // runs on each split panel node exactly.. { UserControlCommonBase uccb = ((c is ExtendedControls.TabStrip) ? ((c as ExtendedControls.TabStrip).CurrentControl) : c) as UserControlCommonBase; if (uccb != null) // tab strip may not have a control set.. { uccb.Closing(); //System.Diagnostics.Debug.WriteLine("Closing " + c.Name + " " + c.GetType().Name + " " + uccb.Name); } }); }
// no cursor.. // Since splitter is used as the primary history window, we need to be more careful due to this being used as the primary cursor // so we by design don't have a cursor at Init on any UCCB. So we must create everything here for the primary, then we have a cursor, and // then load layout can finish the job public override void Init() { TabListSortAlpha = EDDConfig.Instance.SortPanelsByName; // held constant, because we store in each tab splitter the implicit order, can't change it half way thru string defaultview = "H(0.50, U'0,-1', U'1,-1')"; // default is a splitter without any selected panels string splitctrl = SQLiteConnectionUser.GetSettingString(DbWindows, defaultview); SuspendLayout(); // try and make the configured splitter tree SplitContainer sp = ControlHelpersStaticFunc.SplitterTreeMakeFromCtrlString(new BaseUtils.StringParser(splitctrl), MakeSplitContainer, MakeNode, 0); if (sp == null) // string is screwed, nothing was returned. Lets set the default up { sp = ControlHelpersStaticFunc.SplitterTreeMakeFromCtrlString(new BaseUtils.StringParser(defaultview), MakeSplitContainer, MakeNode, 0); } panelPlayfield.Controls.Add(sp); //panelPlayfield.Controls[0].DumpTree(0); ResumeLayout(); BaseUtils.Translator.Instance.Translate(contextMenuStripSplitter, this); }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.SizeControl(Size)"/> protected override void SizeControl(Size parentsize) { // Form autosizer, taking into consideration all objects without autoplacement // and optionally the title text size base.SizeControl(parentsize); if (AutoSize) { Rectangle area = VisibleChildArea(x => (x.Anchor & AnchorType.AutoPlacement) == 0); // get the clients area (ignore autoplaced items and autosize to it) if (AutoSizeToTitle) // if required, take into considering the title text { using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(TextAlign)) { var titlearea = GLOFC.Utils.BitMapHelpers.MeasureStringInBitmap(Text, Font, fmt); area.Width = Math.Max(area.Width, (int)titlearea.Width + (ShowClose ? TitleBarHeight : 0) - ClientLeftMargin); } } Size s = new Size(area.Left + area.Width + AutoSizeClientMargin.Width, area.Top + area.Height + AutoSizeClientMargin.Height); //System.Diagnostics.Debug.WriteLine($"Form {Name} Clients {area} -> {s}"); SetNI(clientsize: s); if (SetMinimumSizeOnAutoSize) { MinimumSize = Size; } } }
internal void Paint(Graphics gr, Rectangle area) { area = new Rectangle(area.Left + HeaderStyle.Padding.Left, area.Top + HeaderStyle.Padding.Top, area.Width - HeaderStyle.Padding.TotalWidth, area.Height - HeaderStyle.Padding.TotalHeight); if (Selected) { using (Brush b = new SolidBrush(HeaderStyle.SelectedColor)) { gr.FillRectangle(b, area); } } else if (HeaderStyle.BackColor != Color.Transparent) { using (Brush b = new SolidBrush(HeaderStyle.BackColor)) { gr.FillRectangle(b, area); } } if (ShowHeaderText) { using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(HeaderStyle.ContentAlignment)) { //System.Diagnostics.Debug.WriteLine($"Draw {Text} {Enabled} {ForeDisabledScaling}"); using (Brush textb = new SolidBrush(HeaderStyle.ForeColor)) { gr.DrawString((rowno + Parent.RowCountOffset).ToString(), HeaderStyle.Font, textb, area, fmt); } } } }
/// <summary> /// Set up a remap of color /// </summary> /// <param name="remap">ColorMap structure for remapping</param> /// <param name="colormatrix">Color remap matrix</param> /// <param name="disabledscaling">Disabled scaling</param> public void SetDrawnBitmapUnchecked(System.Drawing.Imaging.ColorMap[] remap, float[][] colormatrix = null, float disabledscaling = 0.5f) { //System.Diagnostics.Debug.WriteLine("Apply drawn bitmap scaling to " + Name); drawnImageAttributesUnchecked?.Dispose(); drawnImageAttributesDisabled?.Dispose(); ControlHelpersStaticFunc.ComputeDrawnPanel(out drawnImageAttributesUnchecked, out drawnImageAttributesDisabled, disabledscaling, remap, colormatrix); Invalidate(); }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLDataGridViewCell.PerformAutoSize(int)"/> public Size PerformAutoSize(int width) { using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(Style.ContentAlignment)) { fmt.FormatFlags = Style.TextFormat; var size = GLOFC.Utils.BitMapHelpers.MeasureStringInBitmap(text, Style.Font, fmt, new Size(width - Style.Padding.TotalWidth, 20000)); return(new Size((int)(size.Width + 0.99F) + Style.Padding.TotalWidth, (int)(size.Height + 0.99F) + Style.Padding.TotalHeight)); } }
private protected void PaintButtonTextImageFocus(Rectangle buttonarea, Graphics gr, bool paintimage) { if (ShowFocusBox) { if (Focused) { using (var p = new Pen(MouseDownColor) { DashStyle = System.Drawing.Drawing2D.DashStyle.Dash }) { gr.DrawRectangle(p, new Rectangle(buttonarea.Left, buttonarea.Top, buttonarea.Width - 1, buttonarea.Height - 1)); } } buttonarea.Inflate(new Size(-1, -1)); } if (Image != null && paintimage) { base.DrawImage(Image, buttonarea, gr, (Enabled) ? drawnImageAttributesEnabled : drawnImageAttributesDisabled); } if (!string.IsNullOrEmpty(Text)) { using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(TextAlign)) { //System.Diagnostics.Debug.WriteLine($"Draw {Text} {Enabled} {ForeDisabledScaling}"); using (Brush textb = new SolidBrush((Enabled) ? this.ForeColor : this.ForeColor.Multiply(ForeDisabledScaling))) { gr.DrawString(this.Text, this.Font, textb, buttonarea, fmt); } } } if (buttonsymbol != SymbolType.None) { using (var b = new SolidBrush((Enabled) ? this.ForeColor : this.ForeColor.Multiply(ForeDisabledScaling))) { int vcentre = (buttonarea.Top + buttonarea.Bottom) / 2; int hcentre = (buttonarea.Left + buttonarea.Right) / 2; int hright = hcentre + (int)(buttonarea.Width * buttonsymbolsize / 2); int hleft = hcentre - (int)(buttonarea.Width * buttonsymbolsize / 2); int htop = vcentre + (int)(buttonarea.Height * buttonsymbolsize / 2); int hbottom = vcentre - (int)(buttonarea.Height * buttonsymbolsize / 2); if (buttonsymbol == SymbolType.LeftTriangle) { gr.FillPolygon(b, new Point[] { new Point(hleft, vcentre), new Point(hright, htop), new Point(hright, hbottom) }); } else if (buttonsymbol == SymbolType.RightTriangle) { gr.FillPolygon(b, new Point[] { new Point(hright, vcentre), new Point(hleft, htop), new Point(hleft, hbottom) }); } } } }
/// <summary> /// Specify a <see cref="Color"/> <paramref name="remap"/> table and corresponding <see cref="ColorMatrix"/>. /// </summary> /// <param name="remap">An array of <see cref="ColorMap"/> items detailing how colors should be remapped in the /// provided <see cref="ButtonBase.Image"/>.</param> /// <param name="colormatrix">If not null, these values will be used to construct a <see cref="ColorMatrix"/> /// for adjusting the intensity of the displayed <see cref="ButtonBase.Image"/> colors.</param> /// <exception cref="ArgumentNullException">If <paramref name="remap"/> is <c>null</c>.</exception> public void SetDrawnBitmapRemapTable(ColorMap[] remap, float[][] colormatrix = null) { if (remap == null) { throw new ArgumentNullException(nameof(remap)); } DrawnImageAttributesEnabled?.Dispose(); DrawnImageAttributesDisabled?.Dispose(); ControlHelpersStaticFunc.ComputeDrawnPanel(out DrawnImageAttributesEnabled, out DrawnImageAttributesDisabled, _ButtonDisabledScaling, remap, colormatrix); }
/// <summary> /// Set up a remap of color /// </summary> /// <param name="remap">ColorMap structure for remapping</param> /// <param name="colormatrix">Color remap matrix</param> /// <param name="disabledscaling">Disabled scaling</param> public void SetDrawnBitmapRemapTable(System.Drawing.Imaging.ColorMap[] remap, float[][] colormatrix = null, float disabledscaling = 0.5f) { if (remap == null) { throw new ArgumentNullException(nameof(remap)); } drawnImageAttributesEnabled?.Dispose(); drawnImageAttributesDisabled?.Dispose(); ControlHelpersStaticFunc.ComputeDrawnPanel(out drawnImageAttributesEnabled, out drawnImageAttributesDisabled, disabledscaling, remap, colormatrix); Invalidate(); }
private protected void CheckBoxAutoSize() // autosize for a check box display type { SizeF size = SizeF.Empty; using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(TextAlign)) size = GLOFC.Utils.BitMapHelpers.MeasureStringInBitmap(Text, Font, fmt); size = new SizeF(Math.Max(size.Width, 16), Math.Max(size.Height, 16)); int h = (int)(size.Height + 0.999); Size s = new Size((int)(size.Width + 0.999) + h + 4, h + 4); // add h to width to account for the tick //System.Diagnostics.Debug.WriteLine($"Check box {Name} Autosize to {s}"); SetNI(clientsize: s); }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.Paint(Graphics)"/> protected override void Paint(Graphics gr) { if (Text.HasChars()) { using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(TextAlign)) { using (Brush textb = new SolidBrush((Enabled) ? this.ForeColor : this.ForeColor.Multiply(ForeDisabledScaling))) { gr.DrawString(this.Text, this.Font, textb, ClientRectangle, fmt); } } } }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.SizeControlPostChild(Size)"/> protected override void SizeControlPostChild(Size parentsize) { base.SizeControlPostChild(parentsize); if (AutoSize) { using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(TextAlign)) { var texts = GLOFC.Utils.BitMapHelpers.MeasureStringInBitmap(Text, Font, fmt); int textminwidth = (int)texts.Width + GBXoffset; var area = VisibleChildArea(); // all children, find area and set it to it. SetNI(clientsize: new Size(Math.Max(area.Left + area.Right, textminwidth), area.Top + area.Bottom)); } } }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLDataGridViewCell.Paint(Graphics, Rectangle)"/> public void Paint(Graphics gr, Rectangle area) { PaintBack(gr, area); area = new Rectangle(area.Left + Style.Padding.Left, area.Top + Style.Padding.Top, area.Width - Style.Padding.TotalWidth, area.Height - Style.Padding.TotalHeight); using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(Style.ContentAlignment)) { fmt.FormatFlags = Style.TextFormat; //System.Diagnostics.Debug.WriteLine($"Draw {Text} {Enabled} {ForeDisabledScaling}"); using (Brush textb = new SolidBrush(Style.ForeColor)) { gr.DrawString(text, Style.Font, textb, area, fmt); } } }
internal void Paint(Graphics gr, Rectangle area) { area = new Rectangle(area.Left + HeaderStyle.Padding.Left, area.Top + HeaderStyle.Padding.Top, area.Width - HeaderStyle.Padding.TotalWidth, area.Height - HeaderStyle.Padding.TotalHeight); if (HeaderStyle.BackColor != Color.Transparent) { using (Brush b = new SolidBrush(HeaderStyle.BackColor)) { gr.FillRectangle(b, area); } } if (ShowHeaderText) { using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(HeaderStyle.ContentAlignment)) { //System.Diagnostics.Debug.WriteLine($"Draw {Text} {Enabled} {ForeDisabledScaling}"); using (Brush textb = new SolidBrush(HeaderStyle.ForeColor)) { gr.DrawString(text, HeaderStyle.Font, textb, area, fmt); } } } if (ShowGlyph && SortGlyphAscending != null) { using (Brush b = new SolidBrush(HeaderStyle.ForeColor)) { int margin = 2; int size = 10; int hleft = area.Right - size - margin; int hright = hleft + size; int hcentre = (hleft + hright) / 2; int htop = (area.Top + area.Bottom) / 2 - size / 2; int hbottom = htop + size; if (SortGlyphAscending == true) { gr.FillPolygon(b, new Point[] { new Point(hcentre, htop), new Point(hright, hbottom), new Point(hleft, hbottom) }); } else { gr.FillPolygon(b, new Point[] { new Point(hcentre, hbottom), new Point(hleft, htop), new Point(hright, htop) }); } } } }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.DrawBorder(Graphics, Color, float)"/> protected override void DrawBorder(Graphics gr, Color bc, float bw) // normal override, you can overdraw border if required. { int topoffset = this.Text.HasChars() ? (Margin.Top * 3 / 8) : GBMargins; Rectangle rectarea = new Rectangle(Margin.Left, topoffset, Width - Margin.TotalWidth - 1, Height - Margin.Bottom - topoffset - 1); //System.Diagnostics.Debug.WriteLine("Bounds {0} rectarea {1}", bounds, rectarea); using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(TextAlign)) { // work out the area of the text box, given the text width, and the textalign var size = this.Text.HasChars() ? gr.MeasureString(this.Text, this.Font, 10000, fmt) : new SizeF(0, 0); int twidth = (int)(size.Width + 0.99f); bool alignright = TextAlign == ContentAlignment.MiddleRight || TextAlign == ContentAlignment.TopRight || TextAlign == ContentAlignment.BottomRight; Rectangle titlearea = new Rectangle(alignright ? rectarea.Right - twidth - GBXoffset : GBXoffset, 0, twidth, GroupBoxTextHeight); using (var p = new Pen(bc, bw)) { if (this.Text.HasChars()) { gr.DrawLine(p, titlearea.Left - GBXpad, rectarea.Top, rectarea.Left, rectarea.Top); // draw around text gr.DrawLine(p, rectarea.Right, rectarea.Top, titlearea.Right + GBXpad, rectarea.Top); } else { gr.DrawLine(p, rectarea.Left, rectarea.Top, rectarea.Right, rectarea.Top); } gr.DrawLine(p, rectarea.Left, rectarea.Top, rectarea.Left, rectarea.Bottom - 1); gr.DrawLine(p, rectarea.Left, rectarea.Bottom - 1, rectarea.Right, rectarea.Bottom - 1); gr.DrawLine(p, rectarea.Right, rectarea.Bottom - 1, rectarea.Right, rectarea.Top); gr.DrawLine(p, rectarea.Right, rectarea.Bottom - 1, rectarea.Right, rectarea.Top); } if (this.Text.HasChars()) { using (Brush textb = new SolidBrush((Enabled) ? this.ForeColor : ForeColor.Multiply(ForeDisabledScaling))) { gr.DrawString(this.Text, this.Font, textb, titlearea, fmt); } } } }
public TestSplitter() { theme = new ThemeList(); theme.LoadBaseThemes(); theme.SetThemeByName("Elite EuroCaps"); Theme.Current.FontSize = 8.25f; Theme.Current.WindowsFrame = true; InitializeComponent(); string splitctrl = "H(0.50, U'0,-1', U'1,-1')"; // default is a splitter without any selected panels SplitContainer sp = ControlHelpersStaticFunc.SplitterTreeMakeFromCtrlString(new BaseUtils.StringParser(splitctrl), MakeSplitContainer, MakeNode, 0); tabPage1.Controls.Add(sp); //Theme.Current.ApplyStd(this); }
/// <inheritdoc cref="GLOFC.GL4.Controls.GLBaseControl.SizeControl(Size)"/> protected override void SizeControl(Size parentsize) { base.SizeControl(parentsize); if (AutoSize) { SizeF size = SizeF.Empty; if (Text.HasChars()) { using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(TextAlign)) size = GLOFC.Utils.BitMapHelpers.MeasureStringInBitmap(Text, Font, fmt); } Size s = new Size((int)(size.Width + 0.999) + Margin.TotalWidth + Padding.TotalWidth + BorderWidth + 4, (int)(size.Height + 0.999) + Margin.TotalHeight + Padding.TotalHeight + BorderWidth + 4); SetNI(size: s); } }
public void SetDrawnBitmapRemapTable(ColorMap[] remap, float[][] colormatrix = null) { if (IsDisposed) { throw new ObjectDisposedException(this.Name ?? nameof(ExtPanelDrawn)); } drawnImageAttributesDisabled?.Dispose(); drawnImageAttributesDisabled = null; drawnImageAttributesEnabled?.Dispose(); drawnImageAttributesEnabled = null; ControlHelpersStaticFunc.ComputeDrawnPanel(out drawnImageAttributesEnabled, out drawnImageAttributesDisabled, PanelDisabledScaling, remap, colormatrix); if (image != null) { Invalidate(); } }
protected override void OnPaint(PaintEventArgs e) { Rectangle drawarea = ClientRectangle; if (!BorderColor.IsFullyTransparent()) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; Color color1 = BorderColor; Color color2 = BorderColor.Multiply(BorderColorScaling); using (GraphicsPath g1 = ControlHelpersStaticFunc.RectCutCorners(1, 1, ClientRectangle.Width - 2, ClientRectangle.Height - 1, 1, 1)) using (Pen pc1 = new Pen(color1, 1.0F)) e.Graphics.DrawPath(pc1, g1); using (GraphicsPath g2 = ControlHelpersStaticFunc.RectCutCorners(0, 0, ClientRectangle.Width, ClientRectangle.Height - 1, 2, 2)) using (Pen pc2 = new Pen(color2, 1.0F)) e.Graphics.DrawPath(pc2, g2); drawarea.Inflate(-2, -2); } using (Brush br = new SolidBrush(this.TextBackColor)) e.Graphics.FillRectangle(br, drawarea); using (Brush textb = new SolidBrush(this.ForeColor)) { for (int i = 0; i < partlist.Count; i++) { Parts p = partlist[i]; string t = (p.ptype == PartsTypes.Text) ? p.maxstring : datetimevalue.ToString(p.format); if (i == selectedpart) { using (Brush br = new SolidBrush(this.SelectedColor)) e.Graphics.FillRectangle(br, new Rectangle(p.xpos + xstart, drawarea.Y, p.endx - p.xpos, drawarea.Height)); } e.Graphics.DrawString(t, this.Font, textb, new Point(p.xpos + xstart, drawarea.Y + 2)); } } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (!BorderColor.IsFullyTransparent()) { e.Graphics.SmoothingMode = SmoothingMode.Default; Color color1 = BorderColor; Color color2 = BorderColor.Multiply(BorderColorScaling); GraphicsPath g1 = ControlHelpersStaticFunc.RectCutCorners(1, 1, ClientRectangle.Width - 2, ClientRectangle.Height - 1, 1, 1); using (Pen pc1 = new Pen(color1, 1.0F)) e.Graphics.DrawPath(pc1, g1); GraphicsPath g2 = ControlHelpersStaticFunc.RectCutCorners(0, 0, ClientRectangle.Width, ClientRectangle.Height - 1, 2, 2); using (Pen pc2 = new Pen(color2, 1.0F)) e.Graphics.DrawPath(pc2, g2); } }
private protected void ButtonAutoSize(Size extra) // call if autosize as button { SizeF size = SizeF.Empty; if (Text.HasChars()) { using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(TextAlign)) size = GLOFC.Utils.BitMapHelpers.MeasureStringInBitmap(Text, Font, fmt); } if (Image != null && ImageStretch == false) // if we are not stretching the image, we take into account image size { size = new SizeF(size.Width + Image.Width, Math.Max(Image.Height, (int)(size.Height + 0.999))); } Size s = new Size((int)(size.Width + 0.999 + extra.Width) + 4, (int)(size.Height + 0.999 + extra.Height) + 4); SetNI(clientsize: s); }
// no cursor.. // Since splitter is used as the primary history window, we need to be more careful due to this being used as the primary cursor // so we by design don't have a cursor at Init on any UCCB. So we must create everything here for the primary, then we have a cursor, and // then load layout can finish the job public override void Init() { string defaultview = "H(0.50, U'0,-1', U'1,-1')"; // default is a splitter without any selected panels string splitctrl = SQLiteConnectionUser.GetSettingString(DbWindows, defaultview); SuspendLayout(); // try and make the configured splitter tree SplitContainer sp = ControlHelpersStaticFunc.SplitterTreeMakeFromCtrlString(new BaseUtils.StringParser(splitctrl), MakeSplitContainer, MakeNode, 0); if (sp == null) // string is screwed, nothing was returned. Lets set the default up { sp = ControlHelpersStaticFunc.SplitterTreeMakeFromCtrlString(new BaseUtils.StringParser(defaultview), MakeSplitContainer, MakeNode, 0); } panelPlayfield.Controls.Add(sp); //panelPlayfield.Controls[0].DumpTree(0); ResumeLayout(); }
protected override void OnPaint(PaintEventArgs e) { if (firstpaint) { System.ComponentModel.IContainer ic = this.GetParentContainerComponents(); if (ic != null) // yes we have a container object { ic.CopyToolTips(this, new Control[] { textbox }); } firstpaint = true; } using (Brush highlight = new SolidBrush(controlbackcolor)) { e.Graphics.FillRectangle(highlight, ClientRectangle); } base.OnPaint(e); //System.Diagnostics.Debug.WriteLine("Repaint" + Name + ":" + ClientRectangle.Size + " " + textbox.Location + " " + textbox.Size + " " + BorderColor + " " + textbox.BorderStyle); if (OurBorder) { Rectangle clientborder = new Rectangle(0, 0, ClientRectangle.Width, textbox.Height + borderoffset * 2); // paint it around the actual area of the textbox, not just bit Color color1 = BorderColor; Color color2 = BorderColor.Multiply(BorderColorScaling); GraphicsPath g1 = ControlHelpersStaticFunc.RectCutCorners(clientborder.X + 1, clientborder.Y + 1, clientborder.Width - 2, clientborder.Height - 1, 1, 1); using (Pen pc1 = new Pen(color1, 1.0F)) e.Graphics.DrawPath(pc1, g1); GraphicsPath g2 = ControlHelpersStaticFunc.RectCutCorners(clientborder.X, clientborder.Y, clientborder.Width, clientborder.Height - 1, 2, 2); using (Pen pc2 = new Pen(color2, 1.0F)) e.Graphics.DrawPath(pc2, g2); } }
protected override void OnPaint(PaintEventArgs e) { if (firstpaint) { System.ComponentModel.IContainer ic = this.GetParentContainerComponents(); ic?.CopyToolTips(this, new Control[] { textbox }); firstpaint = false; } using (Brush highlight = new SolidBrush(controlbackcolor)) { e.Graphics.FillRectangle(highlight, ClientRectangle); } base.OnPaint(e); //System.Diagnostics.Debug.WriteLine("Repaint" + Name + ":" + ClientRectangle.Size + " " + textbox.Location + " " + textbox.Size + " " + BorderColor + " " + textbox.BorderStyle); if (OurBorder) { Rectangle area = ClientRectangle; Color color1 = BorderColor; Color color2 = BorderColor.Multiply(BorderColorScaling); GraphicsPath g1 = ControlHelpersStaticFunc.RectCutCorners(area.X + 1, area.Y + 1, area.Width - 2, area.Height - 1, 1, 1); using (Pen pc1 = new Pen(color1, 1.0F)) e.Graphics.DrawPath(pc1, g1); GraphicsPath g2 = ControlHelpersStaticFunc.RectCutCorners(area.X, area.Y, area.Width, area.Height - 1, 2, 2); using (Pen pc2 = new Pen(color2, 1.0F)) e.Graphics.DrawPath(pc2, g2); } }
protected override void OnPaint(PaintEventArgs e) { if (firstpaint) { System.ComponentModel.IContainer ic = this.GetParentContainerComponents(); ic?.CopyToolTips(this, new Control[] { this, _cbsystem }); firstpaint = false; } base.OnPaint(e); if (this.FlatStyle != FlatStyle.System) { int extraborder = 1; int texthorzspacing = 1; textBoxBackArea = new Rectangle(ClientRectangle.X + extraborder, ClientRectangle.Y + extraborder, ClientRectangle.Width - 2 * extraborder, ClientRectangle.Height - 2 * extraborder); topBoxTextArea = new Rectangle(ClientRectangle.X + extraborder + texthorzspacing, ClientRectangle.Y + extraborder, ClientRectangle.Width - 2 * extraborder - 2 * texthorzspacing - ScrollBarWidth, ClientRectangle.Height - 2 * extraborder); arrowRectangleArea = new Rectangle(ClientRectangle.Width - ScrollBarWidth - extraborder, ClientRectangle.Y + extraborder, ScrollBarWidth, ClientRectangle.Height - 2 * extraborder); topBoxOutline = new Rectangle(ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width - 1, ClientRectangle.Height - 1); int hoffset = arrowRectangleArea.Width / 3; int voffset = arrowRectangleArea.Height / 3; arrowpt1 = new Point(arrowRectangleArea.X + hoffset, arrowRectangleArea.Y + voffset); arrowpt2 = new Point(arrowRectangleArea.X + arrowRectangleArea.Width / 2, arrowRectangleArea.Y + arrowRectangleArea.Height - voffset); arrowpt3 = new Point(arrowRectangleArea.X + arrowRectangleArea.Width - hoffset, arrowpt1.Y); arrowpt1c = new Point(arrowpt1.X, arrowpt2.Y); arrowpt2c = new Point(arrowpt2.X, arrowpt1.Y); arrowpt3c = new Point(arrowpt3.X, arrowpt2.Y); Brush textb; Pen p, p2; bool todraw = Enabled && Items.Count > 0; if (todraw) { textb = new SolidBrush(this.ForeColor); p = new Pen(BorderColor); p2 = new Pen(ForeColor); p2.Width = ArrowWidth; } else { textb = new SolidBrush(ForeColor.Multiply(0.5F)); p = new Pen(BorderColor.Multiply(0.5F)); p2 = null; } e.Graphics.DrawRectangle(p, topBoxOutline); Color bck; if (todraw) { bck = (mouseover) ? MouseOverBackgroundColor : BackColor; } else { bck = DisableBackgroundDisabledShadingGradient ? BackColor : BackColor.Multiply(0.5F); } Brush bbck; if (FlatStyle == FlatStyle.Popup && !DisableBackgroundDisabledShadingGradient) { bbck = new System.Drawing.Drawing2D.LinearGradientBrush(textBoxBackArea, bck, bck.Multiply(ButtonColorScaling), 90); } else { bbck = new SolidBrush(bck); } e.Graphics.FillRectangle(bbck, textBoxBackArea); //using (Brush test = new SolidBrush(Color.Red)) e.Graphics.FillRectangle(test, topBoxTextArea); // used to check alignment e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if (p2 != null) { if (isActivated) { e.Graphics.DrawLine(p2, arrowpt1c, arrowpt2c); // the arrow! e.Graphics.DrawLine(p2, arrowpt2c, arrowpt3c); } else { e.Graphics.DrawLine(p2, arrowpt1, arrowpt2); // the arrow! e.Graphics.DrawLine(p2, arrowpt2, arrowpt3); } } using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(RtlTranslateAlignment(TextAlign))) { fmt.FormatFlags = StringFormatFlags.NoWrap; e.Graphics.DrawString(this.Text, this.Font, textb, topBoxTextArea, fmt); } e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; bbck.Dispose(); textb.Dispose(); p.Dispose(); if (p2 != null) { p2.Dispose(); } } }
/// <summary> /// Raises the <see cref="ButtonExt.Paint"/> event. /// </summary> /// <param name="pe">A <see cref="PaintEventArgs"/> that contains the event data.</param> protected override void OnPaint(PaintEventArgs pe) { if (FlatStyle != FlatStyle.Popup) // popup style uses custom painting. { base.OnPaint(pe); } else { Rectangle border = ClientRectangle; border.Width--; border.Height--; Rectangle buttonarea = ClientRectangle; buttonarea.Inflate(-1, -1); // inside it. //System.Diagnostics.Debug.WriteLine("Paint " + this.Name + " " + ClientRectangle.ToString() + " MD " + mousedown + " MO " + mouseover); Color colBack = Color.Empty; Color colBorder = Color.Empty; switch (_DrawState) { case DrawState.Disabled: colBack = BackColor.Multiply(0.5F); colBorder = FlatAppearance.BorderColor.Multiply(_ButtonDisabledScaling); break; case DrawState.Normal: default: colBack = BackColor; colBorder = FlatAppearance.BorderColor; break; case DrawState.Hover: colBack = FlatAppearance.MouseOverBackColor; colBorder = FlatAppearance.BorderColor.Multiply(_BorderColorScaling); break; case DrawState.Click: colBack = FlatAppearance.MouseDownBackColor; colBorder = FlatAppearance.BorderColor.Multiply(_BorderColorScaling); break; } using (var b = new LinearGradientBrush(buttonarea, colBack, colBack.Multiply(_ButtonColorScaling), 90)) pe.Graphics.FillRectangle(b, buttonarea); using (var p = new Pen(colBorder)) pe.Graphics.DrawRectangle(p, border); if (Image != null) { if ((Enabled && DrawnImageAttributesEnabled != null) || (!Enabled && DrawnImageAttributesDisabled != null)) { //System.Diagnostics.Debug.WriteLine("ButtonExt " + this.Name + " Draw image with IA"); pe.Graphics.DrawImage(Image, ControlHelpersStaticFunc.ImagePositionFromContentAlignment(ImageAlign, buttonarea, Image.Size), 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, (Enabled) ? DrawnImageAttributesEnabled : DrawnImageAttributesDisabled); } else { pe.Graphics.DrawImage(Image, ControlHelpersStaticFunc.ImagePositionFromContentAlignment(ImageAlign, buttonarea, Image.Size), 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel); } } if (!string.IsNullOrEmpty(Text)) { using (var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(RtlTranslateAlignment(TextAlign))) using (Brush textb = new SolidBrush((Enabled) ? this.ForeColor : this.ForeColor.Multiply(0.5F))) { if (this.UseMnemonic) { fmt.HotkeyPrefix = this.ShowKeyboardCues ? HotkeyPrefix.Show : HotkeyPrefix.Hide; } if (this.AutoEllipsis) { fmt.Trimming = StringTrimming.EllipsisCharacter; } pe.Graphics.DrawString(this.Text, this.Font, textb, buttonarea, fmt); } } if (Focused && ShowFocusCues) { using (var p = new Pen(colBorder)) { Rectangle rcFocus = border; // Thicken the standard border by 1px. rcFocus.Inflate(-1, -1); pe.Graphics.DrawRectangle(p, rcFocus); // Thicken that by an additional 1px, using something similar to ControlPaint.DrawFocusRectangle, but capable of honouring forecolour. rcFocus.Inflate(-1, -1); p.DashStyle = DashStyle.Dash; p.DashPattern = new[] { 1f, 1f }; pe.Graphics.DrawRectangle(p, rcFocus); } } this.OnCustomPaint(pe); } }
protected override void OnPaint(PaintEventArgs e) { if (FlatStyle == FlatStyle.System || FlatStyle == FlatStyle.Standard) { base.OnPaint(e); } else if (DisplayRectangle.Width > 0 && DisplayRectangle.Height > 0) // Popup and Flat are ours, as long as its got size { int topline = DisplayRectangle.Y / 2; Color colorback = BackColor; if (!colorback.IsFullyTransparent()) { Color color2 = (FlatStyle == FlatStyle.Popup) ? colorback.Multiply(BackColorScaling) : BackColor; Rectangle borderrect = ClientRectangle; using (Brush b = new System.Drawing.Drawing2D.LinearGradientBrush(borderrect, colorback, color2, 90)) e.Graphics.FillRectangle(b, borderrect); } if (!BorderColor.IsFullyTransparent()) { Color color1 = BorderColor; Color color2 = BorderColor.Multiply(BorderColorScaling); int textlength = 0; if (this.Text != "") { // +1 for rounding down.. textlength = (int)e.Graphics.MeasureString(this.Text, this.Font).Width + TextPadding * 2 + 1; } int textstart = TextStartPosition; if (textstart == 0) // auto centre { textstart = ClientRectangle.Width / 2 - textlength / 2; // centre } else if (textstart == -1) // left { textstart = 15; } else if (textstart == 1) // right { textstart = ClientRectangle.Width - 15 - textlength; } if (textstart < 4) // need 4 pixels { textstart = 4; } e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; using (GraphicsPath g1 = ControlHelpersStaticFunc.RectCutCorners(1, topline + 1, ClientRectangle.Width - 2, ClientRectangle.Height - topline - 1, 1, 1, textstart - 1, textlength)) using (Pen pc1 = new Pen(color1, 1.0F)) e.Graphics.DrawPath(pc1, g1); using (GraphicsPath g2 = ControlHelpersStaticFunc.RectCutCorners(0, topline, ClientRectangle.Width, ClientRectangle.Height - topline - 1, 2, 2, textstart, textlength)) using (Pen pc2 = new Pen(color2, 1.0F)) e.Graphics.DrawPath(pc2, g2); if (textlength > 0) { e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; int twidth = ClientRectangle.Width - textstart - 4; // What size have we left.. twidth = (textlength < twidth) ? textlength: twidth; // clip Rectangle textarea = new Rectangle(textstart, 0, twidth, DisplayRectangle.Y); using (Brush textb = new SolidBrush(this.ForeColor)) using (StringFormat fmt = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }) { e.Graphics.DrawString(this.Text, this.Font, textb, textarea, fmt); } e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; } } } }
protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); if (compass == null || Enabled != lastdrawnenablestate) // if enabled change (which we don't trap directly due to it being a lower control) redraw as well { PaintCompass(); lastdrawnenablestate = Enabled; } if (compass != null) // designer problems { //System.Diagnostics.Debug.WriteLine("Compass width " + this.Width + " deg width " + WidthDegrees + " pix/deg " + pixelsperdegree); //System.Diagnostics.Debug.WriteLine("Bearing {0} bug {1}", bearing, bug); using (Brush textb = new SolidBrush(this.ForeColor)) { double startdegree = bearing - WidthDegrees / 2; // where do we start int p1start = Bitmappixel((360 + startdegree) % 360); // this whole bit was a bit mind warping! int p1width = Math.Min(compass.Width - p1start, this.Width); // paint all you can up to compass end, limited by control width int left = this.Width - p1width; // and this is what we need from the start of the image.. //System.Diagnostics.Debug.WriteLine("start {0} First paint {1} w {2} then {3}", startdegree, p1start, p1width, left); pe.Graphics.DrawImage(compass, new Rectangle(0, 0, p1width, compass.Height), p1start, 0, p1width, compass.Height, GraphicsUnit.Pixel); if (left > 0) { pe.Graphics.DrawImage(compass, new Rectangle(p1width, 0, left, compass.Height), 0, 0, left, compass.Height, GraphicsUnit.Pixel); } if (!Enabled) { if (disablemessage.Length > 0) { var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(ContentAlignment.MiddleCenter); pe.Graphics.SmoothingMode = textsmoothingmode; pe.Graphics.DrawString(disablemessage, this.Font, textb, new Rectangle(0, compass.Height, this.Width, 24), fmt); fmt.Dispose(); } } else { if (!CentreTickColor.IsFullyTransparent()) { using (Pen p2 = new Pen(CentreTickColor, 4)) pe.Graphics.DrawLine(p2, new Point(this.Width / 2, 0), new Point(this.Width / 2, (compass.Height * centreticklengthpercentage / 100) - 1)); } string distancetext = (double.IsNaN(distance) ? "" : string.Format(distanceformat, distance)) + distancemessage; if (!double.IsNaN(bug)) { using (Brush bbrush = new SolidBrush(BugColor)) { int bugpixel = Bitmappixel(bug); // which pixel in the image is this? int bugx = (bugpixel >= p1start) ? (bugpixel - p1start) : (bugpixel + p1width); // adjust to account for image wrap double delta = (bug - bearing + 360) % 360; //System.Diagnostics.Debug.WriteLine("bug {0} {1} => {2} Delta {3}", p1start, bugpixel, bugx, delta); int bugy = compass.Height; if (bugx < BugSizePixels || bugx >= this.Width - BugSizePixels) { Rectangle r; StringFormat fmt; string text; bool itsleft = bugx < BugSizePixels || (delta > 180 && delta <= 270); int xmargin = 2; if (itsleft) { pe.Graphics.FillPolygon(bbrush, new Point[3] { new Point(0, bugy + BugSizePixels), new Point(BugSizePixels * 2, bugy), new Point(BugSizePixels * 2, bugy + BugSizePixels * 2) }); xmargin += BugSizePixels * 2; r = new Rectangle(xmargin, bugy, this.Width - xmargin, BugSizePixels * 2); fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(ContentAlignment.MiddleLeft); text = ToVisual(bug) + "° " + distancetext; } else { pe.Graphics.FillPolygon(bbrush, new Point[3] { new Point(this.Width - 1, bugy + BugSizePixels), new Point(this.Width - 1 - BugSizePixels * 2, bugy), new Point(this.Width - 1 - BugSizePixels * 2, bugy + BugSizePixels * 2) }); r = new Rectangle(0, bugy, this.Width - BugSizePixels * 2 - xmargin, BugSizePixels * 2); fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(ContentAlignment.MiddleRight); text = distancetext + " " + ToVisual(bug) + "°"; } pe.Graphics.SmoothingMode = textsmoothingmode; pe.Graphics.DrawString(text, this.Font, textb, r, fmt); fmt.Dispose(); } else { pe.Graphics.FillPolygon(bbrush, new Point[3] { new Point(bugx, bugy), new Point(bugx - BugSizePixels, bugy + BugSizePixels * 2), new Point(bugx + BugSizePixels, bugy + BugSizePixels * 2) }); if (distancetext.Length > 0) // if anything to paint { SizeF sz = pe.Graphics.MeasureString(distancetext, Font); Rectangle r; StringFormat fmt; if (bugx > this.Width / 2) // left or right, dependent { fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(ContentAlignment.MiddleRight); r = new Rectangle(0, bugy, bugx - BugSizePixels * 1, BugSizePixels * 2); } else { int xs = bugx + BugSizePixels * 1; r = new Rectangle(xs, bugy, this.Width - xs, BugSizePixels * 2); fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(ContentAlignment.MiddleLeft); } pe.Graphics.SmoothingMode = textsmoothingmode; pe.Graphics.DrawString(distancetext, this.Font, textb, r, fmt); fmt.Dispose(); } } } } else { if (distancetext.Length > 0) { var fmt = ControlHelpersStaticFunc.StringFormatFromContentAlignment(ContentAlignment.MiddleCenter); pe.Graphics.SmoothingMode = textsmoothingmode; pe.Graphics.DrawString(distancetext, this.Font, textb, new Rectangle(0, compass.Height, this.Width, 24), fmt); fmt.Dispose(); } } } } } }