.net - Visual Basic圆形进度条

标签 .net vb.net user-interface progress-bar

我正在尝试制作一个具有良好 UI 的软件,但我对 VB 不专业...... 如何制作圆形进度条?

例如

enter image description here

最佳答案

使用 GDI+ 自己绘制怎么样?

您可以稍后将其转换为您自己的用户控件,但这将帮助您入门。它应该是相当不言自明的:

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

输出

enter image description here

关于.net - Visual Basic圆形进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26928523/

相关文章:

python - 当我将组合框选择为特定值时,如何禁用文本ctrl?

c# - 如何防止 SQL 数据库中的相似(重复)条目?

.net - Windows 文件系统中是否有为每个文件预先计算的哈希值?

c# - 检查属性是否具有指定的属性,然后打印它的值

C# - 求和列表<string[]>

javascript - 如何在 GridView 的 OnLoad 事件上调用 javascript 函数?

vb.net - RichTextBox 中每行文本中的特定单词的颜色

C# (WPF) : Database Relationship Viewer

.net - 在 .NET 中使用 AES 加密 - CryptographicException 表示填充无效且无法删除

java - 如何在Java中从另一个类实现start(Stage)方法?