16

我已经创建了 ac# windows 应用程序并编写了 75% 的代码。该程序允许用户创建流程图,并根据其状态对流程图形状进行着色。我希望它们变成 3d 按钮,例如凝胶按钮 来自网站Webdesign.org

我不想为每个按钮创建一个 PNG,而是想使用画笔或其他技术在 C# 中创建它们,例如:

// Create solid brush.
SolidBrush blueBrush = new SolidBrush(Color.Blue);
// Create points that define polygon.
PointF point1 = new PointF(50.0F, 50.0F);
PointF point2 = new PointF(100.0F, 25.0F);
PointF point3 = new PointF(200.0F, 5.0F);
PointF point4 = new PointF(250.0F, 50.0F);
PointF point5 = new PointF(300.0F, 100.0F);
PointF point6 = new PointF(350.0F, 200.0F);
PointF point7 = new PointF(250.0F, 250.0F);
PointF[] curvePoints = {point1, point2, point3, point4, point5, point6, point7};
// Define fill mode.
FillMode newFillMode = FillMode.Winding;
// Fill polygon to screen.
e.Graphics.FillPolygon(blueBrush, curvePoints, newFillMode);

我知道 WPF 有径向渐变,但我可以在 CGI 中做一些类似的事情吗?

4

2 回答 2

26

WPF不同,GDI+/WinForms 没有RadialGradientBrush. 但是,您可以使用PathGradientBrush.

这是一个例子:

Rectangle bounds = ...;
using (var ellipsePath = new GraphicsPath())
{
    ellipsePath.AddEllipse(bounds);
    using (var brush = new PathGradientBrush(ellipsePath))
    {
        brush.CenterPoint = new PointF(bounds.Width/2f, bounds.Height/2f);
        brush.CenterColor = Color.White;
        brush.SurroundColors = new[] { Color.Red };
        brush.FocusScales = new PointF(0, 0);

        e.Graphics.FillRectangle(brush, bounds);
    }
}

PathGradientBrush很多属性可以试验,以确保你得到你想要的效果。

于 2012-11-29T10:30:52.897 回答
13

看看这篇Codeproject 文章,然后看看路径渐变。

于 2010-08-19T08:20:54.007 回答