【发布时间】:2015-11-23 18:37:51
【问题描述】:
我正在尝试制作一个带有圆形边的标签控件。 这是我在继承自 Label 的 myclass 中的 OnPaint() 重写方法中的代码。
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
LinearGradientBrush brush = new LinearGradientBrush(this.ClientRectangle, GradientColor1, GradientColor2, 90);
e.Graphics.FillRectangle(brush, new Rectangle(new Point(0, 0), new Size(this.Width, this.Height)));
using (GraphicsPath gp = new GraphicsPath())
{
gp.AddArc(new Rectangle(new Point(0, 0), new Size(this.Height, this.Height)), 90, 180);
gp.AddLine(new Point(this.Height / 2, 0), new Point(this.Width - (this.Height / 2), 0));
gp.AddArc(new Rectangle(new Point(this.Width - this.Height, 0), new Size(this.Height, this.Height)), -90, 180);
gp.CloseFigure();
this.Region = new Region(gp);
}
base.OnPaint(e);
}
问题在于它没有平滑两侧的曲线并显示故障。 这是控件的截图:
【问题讨论】:
-
您不能对区域进行反锯齿处理。
-
您真的需要更改区域吗?对于圆形标签,填充圆形背景似乎就足够了,无需更改区域。这样您就可以平滑地填充形状。
-
为了说明 Reza 的观点:Label 对透明度的支持相当不错。只是不要试图让它与不同的控件重叠!
-
@Reza 我需要更改区域以使其变圆。如果您有任何交叉,请分享。
标签: c# winforms graphics controls