如何使用GDI+;(C#,WinForms)
以下是我试图实现的结果: 它应该是基于向量的,因为它可以扩展 以下是我尝试使用PathGradientBrush创建的内容:如何使用GDI+;(C#,WinForms),c#,winforms,gdi+,gradient,gdi,C#,Winforms,Gdi+,Gradient,Gdi,以下是我试图实现的结果: 它应该是基于向量的,因为它可以扩展 以下是我尝试使用PathGradientBrush创建的内容: public partial class Form1 : Form { public Form1() { InitializeComponent(); } double outerRadius = 120; double innerRadius = 110; PointF DistanceFromCent
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double outerRadius = 120;
double innerRadius = 110;
PointF DistanceFromCenter(PointF center, double radius, double angle)
{
double angleInRadians = angle * Math.PI / 180;
return new PointF((float)(center.X + radius * (Math.Cos(angleInRadians))),
(float)(center.Y + radius * (Math.Sin(angleInRadians))));
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
GraphicsPath path = new GraphicsPath();
Point centerPoint = new Point(this.Width / 2, this.Width / 2);
path.AddLine(this.DistanceFromCenter(centerPoint, innerRadius, 0), this.DistanceFromCenter(centerPoint, outerRadius, 0));
path.AddArc(new RectangleF(centerPoint.X - (float)outerRadius, centerPoint.Y - (float)outerRadius, (float)outerRadius * 2, (float)outerRadius * 2), 0, -180);
path.AddLine(this.DistanceFromCenter(centerPoint, outerRadius, -180), this.DistanceFromCenter(centerPoint, innerRadius, -180));
path.AddArc(new RectangleF(centerPoint.X - (float)innerRadius, centerPoint.Y - (float)innerRadius, (float)innerRadius * 2, (float)innerRadius * 2), (float)0, -(float)180);
PathGradientBrush pthGrBrush = new PathGradientBrush(path);
// Set the color at the center of the path to red.
pthGrBrush.CenterColor = Color.FromArgb(255, 255, 0, 0);
// Set the colors of the points in the array.
Color[] colors = {
Color.FromArgb(255, 0, 0, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 0, 255),
Color.FromArgb(255, 255, 255, 255),
Color.FromArgb(255, 0, 0, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 0, 255),
Color.FromArgb(255, 255, 255, 255),
Color.FromArgb(255, 0, 0, 0),
Color.FromArgb(255, 0, 255, 0)};
pthGrBrush.SurroundColors = colors;
// Fill the path with the path gradient brush.
g.FillPath(pthGrBrush, path);
}
}
以下是我得到的结果:
如果有人在寻找,可以通过以下方式实现:。
特别感谢托尔斯滕·古德拉。投票关闭它!这不是构建软件的好方法。你尝试过什么吗?这个问题听起来好像给我密码。。。不要给我们你的要求。提出一个特定的问题。你是对的,你是决定构建它的人。但我们是决定如何处理这个问题的人。你问了这么一个模糊的问题,因为你什么都没试过。如果你想表现得更粗鲁一些,你的问题就结束了。所以试着解释清楚你想要什么,你做了什么,出了什么错,这部分比问题的第一部分更重要。我们想知道你是否有编程方面的知识,或者你是一个新手。毫无疑问,这个问题的答案对很多人来说都很有用。正因为如此,我投+1票。@checho不可行和不想这样做是两回事。因此,人们在将来阅读这篇文章时不会弄错,它在任何winform应用程序上都是完全可行的。