//圆角 private void SetReion() { using (GraphicsPath path = GraphicsPathHelper.CreatePath( new Rectangle(Point.Empty, base.Size), 6, RoundStyle.All, true)) { Region region = new Region(path); path.Widen(Pens.White); region.Union(path); this.Region = region; } }
internal static void DrawGradientRoundRect( Graphics g, Rectangle rect, Color begin, Color end, Color border, Color innerBorder, Blend blend, System.Drawing.Drawing2D.LinearGradientMode mode, int radios, RoundStyle roundStyle, bool drawBorder, bool drawInnderBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, radios, roundStyle, true)) { using (LinearGradientBrush brush = new LinearGradientBrush( rect, begin, end, mode)) { brush.Blend = blend; g.FillPath(brush, path); } if (drawBorder) { using (Pen pen = new Pen(border)) { g.DrawPath(pen, path); } } } if (drawInnderBorder) { rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath( rect, radios, roundStyle, true)) { using (Pen pen = new Pen(innerBorder)) { g.DrawPath(pen, path); } } } }
public static void CreateRegion( Control control, Rectangle bounds, int radius, RoundStyle roundStyle) { using (GraphicsPath path = GraphicsPathHelper.CreatePath( bounds, radius, roundStyle, true)) { Region region = new Region(path); path.Widen(Pens.White); region.Union(path); if (control.Region != null) { control.Region.Dispose(); } control.Region = region; } }
internal static void RenderBackgroundInternal( Graphics g, Rectangle rect, Color baseColor, Color borderColor, Color innerBorderColor, RoundStyle style, int roundWidth, float basePosition, bool drawBorder, bool drawGlass, System.Drawing.Drawing2D.LinearGradientMode mode) { if (drawBorder) { rect.Width--; rect.Height--; } if (rect.Width == 0 || rect.Height == 0) { return; } using (LinearGradientBrush brush = new LinearGradientBrush( rect, Color.Transparent, Color.Transparent, mode)) { Color[] colors = new Color[4]; colors[0] = GetColor(baseColor, 0, 35, 24, 9); colors[1] = GetColor(baseColor, 0, 13, 8, 3); colors[2] = baseColor; colors[3] = GetColor(baseColor, 0, 35, 24, 9); ColorBlend blend = new ColorBlend(); blend.Positions = new float[] { 0.0f, basePosition, basePosition + 0.05f, 1.0f }; blend.Colors = colors; brush.InterpolationColors = blend; if (style != RoundStyle.None) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { g.FillPath(brush, path); } if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == System.Drawing.Drawing2D.LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (GraphicsPath pathTop = GraphicsPathHelper.CreatePath( rectTop, roundWidth, RoundStyle.Top, false)) { using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillPath(brushAlpha, pathTop); } } } if (drawGlass) { RectangleF glassRect = rect; if (mode == System.Drawing.Drawing2D.LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } ControlPaintEx.DrawGlass(g, glassRect, 170, 0); } if (drawBorder) { using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(borderColor)) { g.DrawPath(pen, path); } } rect.Inflate(-1, -1); using (GraphicsPath path = GraphicsPathHelper.CreatePath(rect, roundWidth, style, false)) { using (Pen pen = new Pen(innerBorderColor)) { g.DrawPath(pen, path); } } } } else { g.FillRectangle(brush, rect); if (baseColor.A > 80) { Rectangle rectTop = rect; if (mode == System.Drawing.Drawing2D.LinearGradientMode.Vertical) { rectTop.Height = (int)(rectTop.Height * basePosition); } else { rectTop.Width = (int)(rect.Width * basePosition); } using (SolidBrush brushAlpha = new SolidBrush(Color.FromArgb(128, 255, 255, 255))) { g.FillRectangle(brushAlpha, rectTop); } } if (drawGlass) { RectangleF glassRect = rect; if (mode == System.Drawing.Drawing2D.LinearGradientMode.Vertical) { glassRect.Y = rect.Y + rect.Height * basePosition; glassRect.Height = (rect.Height - rect.Height * basePosition) * 2; } else { glassRect.X = rect.X + rect.Width * basePosition; glassRect.Width = (rect.Width - rect.Width * basePosition) * 2; } ControlPaintEx.DrawGlass(g, glassRect, 200, 0); } if (drawBorder) { using (Pen pen = new Pen(borderColor)) { g.DrawRectangle(pen, rect); } rect.Inflate(-1, -1); using (Pen pen = new Pen(innerBorderColor)) { g.DrawRectangle(pen, rect); } } } } }