Visual basic circular progress bar

前端 未结 4 1289
耶瑟儿~
耶瑟儿~ 2021-02-09 14:49

I\'m trying to make a software with good UI , but i\'m not professional in VB ... How can i make a circular progress bar ?

for Example

4条回答
  •  不知归路
    2021-02-09 15:46

    Here's an example of how to update the progress circular bar just when you need, with no flickering due to refresh.

    Based on Matt's Code

    Simply copy the code in your form Paint Event, properly changing the rectangle size and location to host the circle in your form. Percent is a global variable, when it changes, you can call me.refresh() method to trigger the repaint!

    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
    

提交回复
热议问题