Circular gradients in .NET WinForms app
In my WinForms app (C#) I have a circle (defined by a Rectangle
) that I am presently filling with a solid color. I would like to fill this with a circular (not linear) grad开发者_如何学Pythonient (so one color in the center fades to another color uniformly around the edges).
I have experimented with PathGradientBrush
, but am having no luck (I still see a solid color). If anyone has any sample code that does this, that would be terrific!
I found a solution here.
private void label1_Paint(object sender, PaintEventArgs e)
{
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(label1.ClientRectangle);
PathGradientBrush pgb = new PathGradientBrush(gp);
pgb.CenterPoint = new PointF(label1.ClientRectangle.Width / 2,
label1.ClientRectangle.Height / 2);
pgb.CenterColor = Color.White;
pgb.SurroundingColors = new Color[] { Color.Red };
e.Graphics.FillPath(pgb, gp);
pgb.Dispose();
gp.Dispose();
}
精彩评论