0
我做了一個控件來顯示一個圓形的進度條。 控制如下:DrawArc不閉合邊
- 控制作品用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
我在做什麼錯?
我怎樣纔能有一個完美的圓沒有紅色和藍色酒吧之間的空白?
注:我看到,如果條寬度是1或2,則看不到效果。但是,即使寬度爲20或更多,我也需要控制能夠工作。
感謝所有幫助
這是一個有效的想法,但是這個控制也被用來顯示減小的值 - 這樣我不知道DrawArc命令是否會以相反的方式繪製(從全圓到小於360度......) –
無論如何,我必須考慮我會浪費時間繪製整個圓圈,而不是畫出必需的弧線。 –