2014-11-14 2 views
4

Я пытаюсь создать программное обеспечение с хорошим пользовательским интерфейсом, но я не профессионал в VB ... Как сделать круговой индикатор выполнения?Визуальный базовый круговой индикатор выполнения

для примера

enter image description here

+0

см http://www.codeproject.com/Articles/30625/Circular-Progress-Indicator и также http://www.codeproject.com/Articles/14855/SQL-Server-Circular-Progress-Bar – Plutonix

+0

Это построено с помощью C++, я хочу построить его в визуальном базовом. – faresabb2

+0

они ** не ** в C++; они легко могут быть преобразованы в VB. Дело в том, что они (и другие) уже построены и готовы к использованию; вам не нужно воссоздавать колесо. – Plutonix

ответ

11

Как насчет рисования свой собственный, используя 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 

Выход

enter image description here

+0

Спасибо ... это сработало хорошо, но если вы знаете, как сделать его выше, чем «HighQuality»? – faresabb2

+0

чувак, ты хозяин! –

0

@ faresabb2 В суб Form2.Paint в самом начале кода, положить

e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality 
+0

Спасибо .... я скажу вам, если это сработает. – faresabb2

1

Вот пример того, как обновить круговую полосу прогресса только тогда, когда вам нужно, без мерцания из-за обновления.

на основе Кодекса Мэтта

Просто скопируйте код в форму Paint Event, правильно изменяя размер прямоугольника и место для размещения окружности в вашей форме. Процент - глобальная переменная, когда она изменяется, вы можете вызвать метод 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 
+0

Просто добавьте Dim percent As Single, который может быть пропущен BR1COP –

-1
LabelSec.Text = DateTime.Now.ToString("ss") 
    LabelTime.Text = DateTime.Now.ToString("hh:mm tt") 
    CircularProgressBar1.Value = Convert.ToInt32(LabelSec.Text) 

Попробуйте это ребята ... это код, чтобы использовать ProgressBar как SECON

Смежные вопросы