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 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[] { 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(); } } }
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 e) { if (firstpaint) { System.ComponentModel.IContainer ic = this.GetParentContainerComponents(); if (ic != null) // yes we have a container object { ic.CopyToolTips(this, new Control[] { this, _cbsystem }); } firstpaint = true; } base.OnPaint(e); if (this.FlatStyle != FlatStyle.System) { int extraborder = 1; topBoxTextArea = new Rectangle(ClientRectangle.X + extraborder, ClientRectangle.Y + extraborder, ClientRectangle.Width - 2 * extraborder - 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); topBoxTextTotalArea = new Rectangle(ClientRectangle.X + extraborder, ClientRectangle.Y + extraborder, ClientRectangle.Width - 2 * extraborder, ClientRectangle.Height - 2 * extraborder); 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); SizeF sz = e.Graphics.MeasureString("Represent THIS", this.Font); topBoxTextArea.Y += (topBoxTextArea.Height - (int)sz.Height) / 2; 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 = BackColor.Multiply(0.5F); } Brush bbck; if (FlatStyle == FlatStyle.Popup) { bbck = new System.Drawing.Drawing2D.LinearGradientBrush(topBoxTextTotalArea, bck, bck.Multiply(ButtonColorScaling), 90); } else { bbck = new SolidBrush(bck); } e.Graphics.FillRectangle(bbck, topBoxTextTotalArea); 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 (StringFormat f = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near, FormatFlags = StringFormatFlags.NoWrap }) e.Graphics.DrawString(this.Text, this.Font, textb, topBoxTextArea, f); e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default; bbck.Dispose(); textb.Dispose(); p.Dispose(); if (p2 != null) { p2.Dispose(); } } }