public static void RenderBorder(Graphics g, Rectangle rect, Color borderColor, ButtonBorderType borderType, int radius, RoundStyle roundType) { rect.Width--; rect.Height--; bool simpleRect = (borderType == ButtonBorderType.Rectangle && (roundType == RoundStyle.None || radius < 2)); SmoothingMode newMode = simpleRect ? SmoothingMode.HighSpeed : SmoothingMode.AntiAlias; using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, newMode)) { using (Pen p = new Pen(borderColor)) { if (simpleRect) { g.DrawRectangle(p, rect); } else if (borderType == ButtonBorderType.Ellipse) { g.DrawEllipse(p, rect); } else { using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect(rect, radius, roundType, false)) { g.DrawPath(p, path); } } } } }
private void RenderMainLine(Graphics g, Rectangle rect, Color backColor) { SmoothingMode newMode = (MainLineRadius > 0) ? SmoothingMode.AntiAlias : SmoothingMode.HighSpeed; RoundStyle style = (MainLineRadius > 0) ? RoundStyle.All : RoundStyle.None; using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, newMode)) { using (SolidBrush sb = new SolidBrush(backColor)) { using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect( rect, MainLineRadius, style, false)) { g.FillPath(sb, path); } } if (MainLineDrawBorder) { using (Pen p = new Pen(MainLineBorderColor)) { using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect( rect, MainLineRadius, style, true)) { g.DrawPath(p, path); } } } } }
private void DrawFormBorder(Graphics g) { int width = BorderWidth; Rectangle rect = ClientRectangle; SmoothingMode oldMode = g.SmoothingMode; if (Round != RoundStyle.None) { g.SmoothingMode = SmoothingMode.AntiAlias; } // outter border if (width > 0) { using (Pen p = new Pen(XTheme.FormBorderOutterColor)) { using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect( rect, Radius, Round, true)) { g.DrawPath(p, path); } } } width--; //// inner border //if (width > 0) //{ // using (Pen p = new Pen(XTheme.FormBorderInnerColor)) // { // rect.Inflate(-1, -1); // using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect( // rect, Radius, Round, true)) // { // g.DrawPath(p, path); // } // } //} //width--; g.SmoothingMode = oldMode; // other inside border using (Pen p = new Pen(XTheme.FormBorderInnerColor)) { while (width > 0) { rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect( rect, Radius, Round, true)) { g.DrawPath(p, path); } // g.DrawRectangle(p, rect); width--; } } }
public static void RenderRectangleGlass(Graphics g, Rectangle ownerRect, int ownerRadius, RoundStyle ownerRoundTye, RectangleGlassPosition position, float angle, float glassLengthFactor, Color glassColor, int alpha1, int alpha2) { if (!(glassLengthFactor > 0 && glassLengthFactor < 1)) { throw new ArgumentException("glassLengthFactor must be between 0 and 1, but not include 0 and 1. ", "glassLengthFactor"); } Rectangle rect = CalcGlassRect(ownerRect, position, glassLengthFactor); RoundStyle round = CalcRoundStyle(position, ownerRadius, ownerRoundTye); //if (angle == 0 || angle == 90 || angle == 180 || angle == 270) // angle++; bool simpleRect = (round == RoundStyle.None); SmoothingMode newMode; if (simpleRect) { newMode = SmoothingMode.HighSpeed; } else { newMode = SmoothingMode.AntiAlias; rect.Width--; rect.Height--; } if (rect.Width < 1 || rect.Height < 1) { return; } using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, newMode)) { using (LinearGradientBrush lb = new LinearGradientBrush(rect, Color.FromArgb(alpha1, glassColor), Color.FromArgb(alpha2, glassColor), angle)) { if (simpleRect) { g.FillRectangle(lb, rect); } else { using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect(rect, ownerRadius, round, false)) { g.FillPath(lb, path); } } } } }
private void SetFormReion() { if (base.Region != null) { base.Region.Dispose(); } using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect( new Rectangle(Point.Empty, base.Size), 16, RoundStyle.All, false)) { this.Region = new Region(path); } }
private void DrawFormBackground(Graphics g) { SmoothingMode oldMode = g.SmoothingMode; if (Round != RoundStyle.None) { g.SmoothingMode = SmoothingMode.AntiAlias; } using (SolidBrush sb = new SolidBrush(XTheme.FormBackColor)) { using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect( ClientRectangle, Radius, Round, false)) { g.FillPath(sb, path); } } g.SmoothingMode = oldMode; }
private void SetFormRegion() { if (base.Region != null) { base.Region.Dispose(); } Rectangle rect = new Rectangle(Point.Empty, base.Size); GraphicsPath path; if (XTheme.UseDefaultTopRoundingFormRegion) { path = GraphicsPathHelper.CreateTopRoundedPathForFormRegion(rect); } else { path = GraphicsPathHelper.CreateRoundedRect(rect, Radius, Round, false); } this.Region = new Region(path); }
public static void RenderFlatBackground(Graphics g, Rectangle rect, Color backColor, ButtonBorderType borderType, int radius, RoundStyle roundType) { SmoothingMode newMode; bool simpleRect = (borderType == ButtonBorderType.Rectangle && (roundType == RoundStyle.None || radius < 2)); if (simpleRect) { newMode = SmoothingMode.HighSpeed; } else { newMode = SmoothingMode.AntiAlias; rect.Width--; rect.Height--; } using (NewSmoothModeGraphics ng = new NewSmoothModeGraphics(g, newMode)) { using (SolidBrush sb = new SolidBrush(backColor)) { if (simpleRect) { g.FillRectangle(sb, rect); } else if (borderType == ButtonBorderType.Ellipse) { g.FillEllipse(sb, rect); } else { using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect(rect, radius, roundType, false)) { g.FillPath(sb, path); } } } } }
/// <summary> /// to make the client area to have 3D view /// </summary> private void DrawInsetClientRect(Graphics g) { int x = BorderWidth; int y = BorderWidth + CaptionHeight; int w = ClientSize.Width - BorderWidth * 2; int h = ClientSize.Height - BorderWidth * 2 - CaptionHeight; Rectangle clientRect = new Rectangle(x, y, w, h); clientRect.Width--; clientRect.Height--; Color inner = ColorHelper.GetDarkerColor(this.BackColor, 20); clientRect.Inflate(1, 1); using (Pen p1 = new Pen(inner)) { // g.DrawRectangle(p1, clientRect); using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect( clientRect, Radius, Round, true)) { g.DrawPath(p1, path); } } Color outter = Color.FromArgb(80, 255, 255, 255); clientRect.Inflate(1, 1); using (Pen p2 = new Pen(outter)) { //g.DrawRectangle(p2, clientRect); using (GraphicsPath path = GraphicsPathHelper.CreateRoundedRect( clientRect, Radius, Round, true)) { g.DrawPath(p2, path); } } }