开发者

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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜