【发布时间】:2017-07-06 00:57:33
【问题描述】:
我做了一个控件来显示一个圆形进度条。 控件如下图:
- 该控件适用于 2 个 ARC:
- 其中一个显示当前值(蓝色)
- 另一个显示剩余值(红色)。
两者都适用于图形库中的 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
我做错了什么?
如果没有红色和蓝色条之间的空白,我怎样才能得到一个完美的圆圈?
注意:我看到如果 bar-width 为 1 或 2,则看不到效果。但即使宽度为 20 或更大,我也需要让控件能够工作。
感谢您的帮助
【问题讨论】: