Gradient Brush Ball : PathGradientBrush « 2D Graphics « C# / C Sharp






Gradient Brush Ball

 

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

class BouncingGradientBrushBall : Form {
    public static void Main() {
        Application.Run(new BouncingGradientBrushBall());
    }
    public BouncingGradientBrushBall() {
        ResizeRedraw = true;
    }
    protected override void OnPaint(PaintEventArgs pea) {
        GraphicsPath path = new GraphicsPath();
        Rectangle rect = new Rectangle(10, 10, 30, 30);
        path.AddEllipse(rect);

        PathGradientBrush pgbrush = new PathGradientBrush(path);
        pgbrush.CenterPoint = new PointF((rect.Left + rect.Right) / 3,
                                         (rect.Top + rect.Bottom) / 3);
        pgbrush.CenterColor = Color.White;
        pgbrush.SurroundColors = new Color[] { Color.Red };

        pea.Graphics.FillRectangle(pgbrush, rect);
    }
}

 








Related examples in the same category

1.CenterColor
2.Triangle Gradient Brush
3.Star Gradient Brush
4.Triangle Tile
5.Square Tile
6.Two-Triangle Tile