Page 1 of 2

Multi Colored Progress Bar

Posted: Tue Aug 17, 2010 1:52 am
by Bogoh67
First New Project. Then New Class. Delete All Code And Add This
Code: Select all
Imports System.Drawing.Drawing2D
Class MultiColorProgressBar



    Inherits Control

#Region " Properties "
    Private _Maximum As Double = 100
    Public Property Maximum() As Double
        Get
            Return _Maximum
        End Get
        Set(ByVal v As Double)
            _Maximum = v
            Value = _Current / v * 100
            Invalidate()
        End Set
    End Property
    Private _Current As Double
    Public Property Current() As Double
        Get
            Return _Current
        End Get
        Set(ByVal v As Double)
            _Current = v
            Value = v / _Maximum * 100
            Invalidate()
        End Set
    End Property
    Private _Value As Integer
    Public Property Value() As Double
        Get
            Return _Value
        End Get
        Set(ByVal v As Double)
            If v < 0 Then v = 0 Else If v > 100 Then v = 100
            _Value = Convert.ToInt32(v)
            _Current = v * 0.01 * _Maximum
            If Width > 0 Then UpdateProgress()
            Invalidate()
        End Set
    End Property

    Dim C2 As Color = Color.FromArgb(6, 96, 149) 'Dark Color
    Public Property Color1() As Color
        Get
            Return C2
        End Get
        Set(ByVal v As Color)
            C2 = v
            UpdateColors()
            Invalidate()
        End Set
    End Property
    Dim C3 As Color = Color.FromArgb(70, 167, 220) 'Light color
    Public Property Color2() As Color
        Get
            Return C3
        End Get
        Set(ByVal v As Color)
            C3 = v
            UpdateColors()
            Invalidate()
        End Set
    End Property

#End Region

    Protected Overrides Sub OnPaintBackground(ByVal pevent As PaintEventArgs)
    End Sub

    Dim G As Graphics, B As Bitmap, R1, R2 As Rectangle, X As ColorBlend
    Dim C1 As Color, P1, P2, P3 As Pen, B1, B2 As LinearGradientBrush, B3 As SolidBrush
    Sub New()

        C1 = Color.FromArgb(22, 22, 22) 'Background
        P1 = New Pen(Color.FromArgb(70, Color.White), 2)
        P2 = New Pen(C2)
        P3 = New Pen(Color.FromArgb(49, 49, 49)) 'Highlight
        B3 = New SolidBrush(Color.FromArgb(100, Color.White))
        X = New ColorBlend(4)
        X.Colors = New Color() {C2, C3, C3, C2}
        X.Positions = New Single() {0.0F, 0.1F, 0.9F, 1.0F}
        R2 = New Rectangle(2, 2, 2, 2)
        B2 = New LinearGradientBrush(R2, Nothing, Nothing, 180.0F)
        B2.InterpolationColors = X

    End Sub

    Sub UpdateColors()
        P2.Color = C2
        X.Colors = New Color() {C2, C3, C3, C2}
        B2.InterpolationColors = X
    End Sub

    Protected Overrides Sub OnSizeChanged(ByVal e As System.EventArgs)
        R1 = New Rectangle(0, 1, Width, 4)
        B1 = New LinearGradientBrush(R1, Color.FromArgb(60, Color.Black), Color.Transparent, 90.0F)
        UpdateProgress()
        Invalidate()
        MyBase.OnSizeChanged(e)
    End Sub

    Sub UpdateProgress()
        If _Value = 0 Then Return
        R2 = New Rectangle(2, 2, Convert.ToInt32((Width - 4) * (_Value * 0.01)), Height - 4)
        B2 = New LinearGradientBrush(R2, Nothing, Nothing, 180.0F)
        B2.InterpolationColors = X
    End Sub

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        B = New Bitmap(Width, Height)
        G = Graphics.FromImage(B)

        G.Clear(C1)

        G.FillRectangle(B1, R1)

        If _Value > 0 Then
            G.FillRectangle(B2, R2)

            G.FillRectangle(B3, 2, 3, R2.Width, 4)
            G.DrawRectangle(P1, 4, 4, R2.Width - 4, Height - 8)

            G.DrawRectangle(P2, 2, 2, R2.Width - 1, Height - 5)
        End If

        G.DrawRectangle(P3, 0, 0, Width - 1, Height - 1)

        e.Graphics.DrawImage(B, 0, 0)
        G.Dispose()
        B.Dispose()
    End Sub

End Class

Re: Multi Colored Progress Bar

Posted: Tue Aug 17, 2010 2:47 am
by zachman61
nice im going to use this cooll;

Re: Multi Colored Progress Bar

Posted: Tue Aug 17, 2010 9:33 am
by XTechVB
thanks dude

Re: Multi Colored Progress Bar

Posted: Tue Aug 17, 2010 10:10 am
by NecroPhis
thanx useful for me cooll; cooll;

Re: Multi Colored Progress Bar

Posted: Tue Aug 17, 2010 3:11 pm
by Bogoh67
ur welcome thanks for posting

Re: Multi Colored Progress Bar

Posted: Tue Aug 17, 2010 10:41 pm
by Agust1337
thanks for posting this mate :)

Re: Multi Colored Progress Bar

Posted: Tue Aug 17, 2010 10:44 pm
by Codex
nice, does it have increment?

Re: Multi Colored Progress Bar

Posted: Thu Aug 19, 2010 1:27 am
by jtlusco
can someone tell me how to get this to work properly

Re: Multi Colored Progress Bar

Posted: Thu Aug 19, 2010 1:58 am
by Bogoh67
just add a new class, delete all the new classes code add my code run program stop program and u have a new item in your toolbox

Re: Multi Colored Progress Bar

Posted: Thu Aug 19, 2010 8:36 am
by un kn0 wn
nice progressbar m8 but im not guna use it.