clovett

[

posted this sample

](https://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=d2bd8858-97c7-4a77-96eb-5d86d3b022d4)

of a progress bar that does not progress 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
        Get
            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
        Get
            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
        Get
            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, _
            LinearGradientMode.Horizontal)
        b.WrapMode = Drawing.Drawing2D.WrapMode.TileFlipX
        b.TranslateTransform(Position, 0, MatrixOrder.Append)
        e.Graphics.FillRectangle(b, 0, 0, Me.Width, Me.Height)
        b.Dispose()
        MyBase.OnPaint(e)
    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
        Me.Invalidate()
    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
            tmr.Start()
        Else
            If Not tmr Is Nothing Then
                tmr.Stop()
            End If
        End If
        MyBase.OnVisibleChanged(e)
    End Sub
End Class