我做了一个控件来显示一个圆形进度条。 控件如下所示:
两者都与图形库中的ProgressPen和DrawArc一起使用。
问题在于,正如您所看到的,两个弧的边缘之间有一些像素,它们实际上没有连接 - 尽管角度是一个双数,并且设置精确到360度。
在上图中,蓝色为90.0度,红色为270.0度(圆圈内的25%仅为字体测试)。
如何避免这种行为?
我用来绘制两个弧的例程是:
Private Sub UserControl1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
e.Graphics.PixelOffsetMode = Drawing2D.PixelOffsetMode.HighQuality
e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
e.Graphics.CompositingMode = Drawing2D.CompositingMode.SourceOver
e.Graphics.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
Dim NewRect As Rectangle = New Rectangle(m_X + (20 / 2.0f), m_Y + (20 / 2.0f), m_Width - 20, m_Height - 20)
DrawProgress(e.Graphics, NewRect, m_Valor)
End Sub
Private Sub DrawProgress(g As Graphics, rect As Rectangle, percentage As integer)
Dim progressAngle As single = CSng(360.000F / 100.000F * percentage)
Dim remainderAngle As single = 360.000F - progressAngle
'create pens to use for the arcs
Using progressPen As New Pen(m_Color, 20), remainderPen As New Pen(m_EmptyColor, 20)
g.DrawArc(progressPen, rect, -90.000F, progressAngle)
g.DrawArc(remainderPen, rect, progressAngle - 90.000F, remainderAngle)
progressPen.Dispose
End Using
End Sub
我做错了什么?
如果没有RED和BLUE条之间的空白区域,我怎么能有一个完美的圆圈?
注意:我看到如果条形宽度为1或2,则看不到效果。但是我需要让控件能够工作,即使宽度是20或更多。
感谢您的帮助
答案 0 :(得分:0)
我只是将蓝色绘制成一个完整的圆圈并在其上叠加红色弧。