public static void FillPath(Graphics g, GraphicsPath path, Rectangle rect, GradientColor color) { using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(rect, color.First, color.Second, LinearGradientMode.Vertical)) { linearGradientBrush.Blend.Factors = color.Factors; linearGradientBrush.Blend.Positions = color.Positions; g.FillPath(linearGradientBrush, path); } }
public static void FillRectangle(Graphics g, Rectangle rect, GradientColor color) { if (rect.Width > 0 && rect.Height > 0 && g != null) { using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(rect, color.First, color.Second, LinearGradientMode.Vertical)) { linearGradientBrush.Blend.Factors = color.Factors; linearGradientBrush.Blend.Positions = color.Positions; g.FillRectangle(linearGradientBrush, rect); } } }
public static void FillRectangle(Graphics g, RoundRectangle roundRect, GradientColor color) { if (roundRect.Rect.Width > 0 && roundRect.Rect.Height > 0) { using (GraphicsPath path = roundRect.ToGraphicsBezierPath()) { using (LinearGradientBrush linearGradientBrush = new LinearGradientBrush(roundRect.Rect, color.First, color.Second, LinearGradientMode.Vertical)) { linearGradientBrush.Blend.Factors = color.Factors; linearGradientBrush.Blend.Positions = color.Positions; g.FillPath(linearGradientBrush, path); } } } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); int num = (BorderWidth > 0) ? BorderWidth : 0; Graphics graphics = e.Graphics; GDIHelper.InitializeGraphics(graphics); GradientColor color = new GradientColor(_BackBeginColor, _BackEndColor, null, null); Rectangle rect = new Rectangle(0, 0, base.Size.Width - 1, base.Size.Height - 1); RoundRectangle roundRect = new RoundRectangle(rect, new CornerRadius(_CornerRadius)); GDIHelper.FillRectangle(graphics, roundRect, color); if (_BorderWidth > 0) { rect.X += _BorderWidth - 1; rect.Y += _BorderWidth - 1; rect.Width -= _BorderWidth - 1; rect.Height -= _BorderWidth - 1; GDIHelper.DrawPathBorder(graphics, new RoundRectangle(rect, new CornerRadius(_CornerRadius)), _BorderColor, BorderWidth); } }
public static void FillPath(Graphics g, RoundRectangle roundRect, Color color1, Color color2, Blend blend) { GradientColor color3 = new GradientColor(color1, color2, blend.Factors, blend.Positions); FillRectangle(g, roundRect, color3); }