GDI和winforms中的c#径向梯度笔刷效应
我创建了一个c#windows应用程序,并编写了75%的代码。该程序允许用户创建流程图,并根据其状态对流程图形状进行着色。我想让它们变成3d按钮,比如网站上的按钮 我不想为每个按钮创建PNG,而是想使用画笔或其他技术在C#中创建它们,例如:GDI和winforms中的c#径向梯度笔刷效应,c#,winforms,gdi,brush,C#,Winforms,Gdi,Brush,我创建了一个c#windows应用程序,并编写了75%的代码。该程序允许用户创建流程图,并根据其状态对流程图形状进行着色。我想让它们变成3d按钮,比如网站上的按钮 我不想为每个按钮创建PNG,而是想使用画笔或其他技术在C#中创建它们,例如: // Create solid brush. SolidBrush blueBrush = new SolidBrush(Color.Blue); // Create points that define polygon. PointF point1 = n
// 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中做一些类似的事情吗?看看这个,然后看看路径梯度 与之不同,GDI+/WinForms没有RadialGradientBrush
。但是,您可以使用一个
下面是一个例子:
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
有许多属性可供实验,以确保您获得所追求的效果。谢谢,我会尝试一下。我想您指的是“GDI+”而不是“CGI”?不过这有很大的区别。WF的PathGradientBrush
不会在路径外部绘制。WPF的RadialGradientBrush
。因此,根据您的需求,到目前为止可能无法实现相同的效果。