回答
如何只使用GDI +繪製自己。
您可以稍後將其轉換爲您自己的usercontrol,但這會讓您開始。它應該是相當自我解釋:
Private Sub Form2_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
DrawProgress(e.Graphics, New Rectangle(5, 5, 60, 60), 40)
DrawProgress(e.Graphics, New Rectangle(80, 5, 60, 60), 80)
DrawProgress(e.Graphics, New Rectangle(155, 5, 60, 60), 57)
End Sub
Private Sub DrawProgress(g As Graphics, rect As Rectangle, percentage As Single)
'work out the angles for each arc
Dim progressAngle = CSng(360/100 * percentage)
Dim remainderAngle = 360 - progressAngle
'create pens to use for the arcs
Using progressPen As New Pen(Color.LightSeaGreen, 2), remainderPen As New Pen(Color.LightGray, 2)
'set the smoothing to high quality for better output
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
'draw the blue and white arcs
g.DrawArc(progressPen, rect, -90, progressAngle)
g.DrawArc(remainderPen, rect, progressAngle - 90, remainderAngle)
End Using
'draw the text in the centre by working out how big it is and adjusting the co-ordinates accordingly
Using fnt As New Font(Me.Font.FontFamily, 14)
Dim text As String = percentage.ToString + "%"
Dim textSize = g.MeasureString(text, fnt)
Dim textPoint As New Point(CInt(rect.Left + (rect.Width/2) - (textSize.Width/2)), CInt(rect.Top + (rect.Height/2) - (textSize.Height/2)))
'now we have all the values draw the text
g.DrawString(text, fnt, Brushes.Black, textPoint)
End Using
End Sub
輸出
謝謝......這工作得很好,但如果你知道如何讓它比「HighQuality」更高? – faresabb2
老兄,你是高手! –
@ faresabb2在在代碼的最開始的Form2.Paint子,把
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
謝謝....我會告訴你它是否有效。 – faresabb2
這裏是一個如何在需要時更新進度循環欄的示例,而不會因刷新而閃爍。
基於馬特的代碼
只要將代碼拷貝到您的形式Paint事件中,適當地改變矩形的大小和位置,以託管在表單中的圈子。 百分比是一個全局變量,當它發生變化時,可以調用me.refresh()方法來觸發重繪!
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles MyBase.Paint
Dim g As Graphics = e.Graphics
Dim rect As New Rectangle(70, 45, 90, 90)
Dim curvatura_progress = CSng(360/100 * percent)
Dim curvatura_rimanente = 360 - curvatura_progress
Using tratto_progresso As New Pen(Color.Lime, 4), tratto_rimanente As New Pen(Color.White, 4)
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
g.DrawArc(tratto_progresso, rect, -90, curvatura_progress)
g.DrawArc(tratto_rimanente, rect, curvatura_progress - 90, curvatura_rimanente)
End Using
Using fnt As New Font(Me.Font.FontFamily, 14)
Dim text As String = percent.ToString + "%"
Dim textSize = g.MeasureString(text, fnt)
Dim textPoint As New Point(CInt(rect.Left + (rect.Width/2) - (textSize.Width/2)), CInt(rect.Top + (rect.Height/2) - (textSize.Height/2)))
g.DrawString(text, fnt, Brushes.Black, textPoint)
End Using
End Sub
只需添加Dim percent As Single這可能會錯過BR1COP –
LabelSec.Text = DateTime.Now.ToString("ss")
LabelTime.Text = DateTime.Now.ToString("hh:mm tt")
CircularProgressBar1.Value = Convert.ToInt32(LabelSec.Text)
試試這個傢伙...這是使用進度爲塞康代碼
- 1. 圓形進度條
- 2. 圓形UILabel圓形進度條
- 3. 圓形進度條css
- 4. 圓形邊框進度條
- 5. WPF:圓形進度條
- 6. 圓形進度條(css)
- 7. 彎曲圓形進度條
- 8. 圓形進度條Android
- 9. Android - 圓角方形線條進度條
- 10. CSS或jQuery/JavaScript橢圓形/圓形方形進度條
- 11. c#xamarin圓形進度條 - Android
- 12. 圓形進度條大小對齊
- 13. Android圓形進度條大小
- 14. jQuery動畫圓形進度條
- 15. 角2中的圓形進度條
- 16. Xamarin.UWP:如何製作圓形進度條
- 17. 使用Tkinter的圓形進度條?
- 18. 使用壁畫的圓形進度條
- 19. GWT中的圓形進度條
- 20. 帶指示器的圓形進度條
- 21. Java中的圓形進度條顯示
- 22. 在圓形進度條中清除progressDrawable
- 23. 使用JavaScript的圓形進度條
- 24. 圓形進度條中的漸變
- 25. Windows窗體中的圓形進度條
- 26. 旋轉圓形進度條對面
- 27. 用html5製作圓形進度條sgg
- 28. Unity 3D中的圓形進度條 - UnityScript
- 29. 動態擴展視覺基本形式
- 30. 圓形進度條中的圓形邊Android
看到http://www.codeproject.com/Articles/30625/Circular-Progress-Indicator和也是http://www.codeproject.com/Articles/14855/SQL-Server-Circular-Progress-Bar – Plutonix
這是用C++構建的,我想用visual basic構建它。 – faresabb2
它們在**中不是**;他們可以很容易地轉換爲VB。關鍵是他們(和其他人)已經建成並準備使用;你不必重新創建輪子。 – Plutonix