Multi Colored Progress Bar

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
12 posts Page 1 of 2
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Multi Colored Progress Bar
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
User avatar
zachman61
VIP - Donator
VIP - Donator
Posts: 1892
Joined: Wed Dec 16, 2009 9:56 pm

Re: Multi Colored Progress Bar
zachman61
nice im going to use this cooll;
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that :)
User avatar
XTechVB
VIP - Site Partner
VIP - Site Partner
Posts: 727
Joined: Thu May 20, 2010 10:32 am

Re: Multi Colored Progress Bar
XTechVB
thanks dude
You can find me on Facebook or on Skype mihai_92b
User avatar
NecroPhis
VIP - Donator
VIP - Donator
Posts: 345
Joined: Sun Aug 08, 2010 1:14 pm

Re: Multi Colored Progress Bar
NecroPhis
thanx useful for me cooll; cooll;
Image
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: Multi Colored Progress Bar
Bogoh67
ur welcome thanks for posting
User avatar
Agust1337
Coding God
Coding God
Posts: 2456
Joined: Fri Feb 19, 2010 8:18 pm

Re: Multi Colored Progress Bar
Agust1337
thanks for posting this mate :)
Top-notch casual Dating
User avatar
Codex
Coding God
Coding God
Posts: 2028
Joined: Wed Mar 31, 2010 5:50 pm

Re: Multi Colored Progress Bar
Codex
nice, does it have increment?
We shall let the revolution begin.. the revolution for freedom, freedom against censorship. We shall fight in the fields and in the streets, we shall fight in the hills; we shall never surrender
User avatar
jtlusco
VIP - Donator
VIP - Donator
Posts: 138
Joined: Mon Jul 12, 2010 11:28 pm

Re: Multi Colored Progress Bar
jtlusco
can someone tell me how to get this to work properly
Have you been scripted today
Image
User avatar
Bogoh67
VIP - Site Partner
VIP - Site Partner
Posts: 656
Joined: Sun Apr 18, 2010 8:20 pm

Re: Multi Colored Progress Bar
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
User avatar
un kn0 wn
VIP - Donator
VIP - Donator
Posts: 269
Joined: Mon Mar 29, 2010 6:12 pm

Re: Multi Colored Progress Bar
un kn0 wn
nice progressbar m8 but im not guna use it.
12 posts Page 1 of 2
Return to “Tutorials”