110,567
社区成员
发帖
与我相关
我的任务
分享
private void DrawPeiRect(Graphics g, RectangleF rect)
{
//生成一个圆角矩形渐变画刷
PathGradientBrush pb = new PathGradientBrush(GetFilletRect(rect, 20f, 20f, 20f, 20f));
//从外到内渐变颜色
Color[] colors =
{
Color.FromArgb(120, 247, 190, 247),
Color.FromArgb(255, 249, 195, 247),
Color.FromArgb(255, 249, 238, 247),
Color.FromArgb(255, 249, 238, 247),
};
//从内到外渐变位置百分比
float[] relativePositions =
{
0f,
0.03f,
0.15f,
1f,
};
ColorBlend colorBlend = new ColorBlend();
colorBlend.Colors = colors;
colorBlend.Positions = relativePositions;
pb.InterpolationColors = colorBlend;
//去圆角毛刺
g.SmoothingMode = SmoothingMode.HighQuality;
g.FillPath(pb, GetFilletRect(rect, 20f, 20f, 20f, 20f));
}
private GraphicsPath GetFilletRect(RectangleF r, float r1, float r2, float r3, float r4)
{
float x = r.X, y = r.Y, w = r.Width, h = r.Height;
GraphicsPath rr = new GraphicsPath();
rr.AddBezier(x, y + r1, x, y, x + r1, y, x + r1, y);
rr.AddLine(x + r1, y, x + w - r2, y);
rr.AddBezier(x + w - r2, y, x + w, y, x + w, y + r2, x + w, y + r2);
rr.AddLine(x + w, y + r2, x + w, y + h - r3);
rr.AddBezier(x + w, y + h - r3, x + w, y + h, x + w - r3, y + h, x + w - r3, y + h);
rr.AddLine(x + w - r3, y + h, x + r4, y + h);
rr.AddBezier(x + r4, y + h, x, y + h, x, y + h - r4, x, y + h - r4);
rr.AddLine(x, y + h - r4, x, y + r1);
return rr;
}