Indicating Infinite Progress, or lack thereof


posted this sample

 of a progress bar that does not
to GDN at some point in the past and I had occasion to use it
today. Using irrational coder logic, I decided that converting it to VB, so I
could place it directly in my application, was faster than modifying his sample
into a component…

Anyway, explanations aside; here is the
code in VB

Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class InfiniteProgress
    Inherits System.Windows.Forms.Control
    Dim WithEvents tmr As Timer
    Dim m_Color1 As Color = Color.White
    Dim m_Color2 As Color = Color.Blue
    Dim m_Increment As Integer = 5

    <ComponentModel.Category("Appearance")> _
    Public Property Color1() As Color
            Return m_Color1
        End Get
        Set(ByVal Value As Color)
            m_Color1 = Value
        End Set
    End Property

    <ComponentModel.Category("Appearance")> _
    Public Property Color2() As Color
            Return m_Color2
        End Get
        Set(ByVal Value As Color)
            m_Color2 = Value
        End Set
    End Property

    <ComponentModel.Category("Appearance")> _
    Public Property Increment() As Integer
            Return m_Increment
        End Get
        Set(ByVal Value As Integer)
            m_Increment = Value
        End Set
    End Property

    Dim Position As Single = 0

    Public Sub New()
        Me.SetStyle(ControlStyles.DoubleBuffer, True)

    End Sub

    Protected Overrides Sub OnPaint( _
            ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim b As New LinearGradientBrush( _
            Me.Bounds, Me.Color1, Me.Color2, _
        b.WrapMode = Drawing.Drawing2D.WrapMode.TileFlipX
        b.TranslateTransform(Position, 0, MatrixOrder.Append)
        e.Graphics.FillRectangle(b, 0, 0, Me.Width, Me.Height)
    End Sub

    Private Sub tmr_Tick(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles tmr.Tick
        Position += m_Increment
        If Position > Me.Width Then
            Position = -Me.Width
        End If
    End Sub

    Protected Overrides Sub _
            OnVisibleChanged(ByVal e As System.EventArgs)
        If Me.Visible Then
            If tmr Is Nothing Then
                tmr = New Timer()
                tmr.Interval = 20
            End If
            If Not tmr Is Nothing Then
            End If
        End If
    End Sub
End Class

Author: Duncan Mackenzie

I'm the Developer Lead for the Channel 9 team, formerly worked on MSDN as a developer, content strategist and author.

Leave a Reply