Results 1 to 5 of 5

Thread: Looking for a Progress Bar with a Difference

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224

    Question

    Hi guys
    I was wondering if anyone knows of any nice alternatives to the MS Progress Bar.
    Thanks a lot for any suggestions

    Cheers
    JK

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    I do mine with 2 picturebox controls, a back dark greyish shadowy one, then a picture in the second, front one.

    For instance, I've just done a lottery number generator (not the hardest project in the world, but...). For the setup, I downloaded a pic of lottery balls & used this in the front picture box. You can then use the picture1.left = picture1.left + 1 method to make this bar stretch.


    It's a lot of coding, but gives a worthwhile view like the one you get when installing Go!Zilla.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    It's pretty easy to make your own progressbar using a PictureBox. So you don't need the bulky Windows Common Control.
    I resently wrote a class that works just like a smooth progressbar but it uses a PictureBox.
    Here's the code:
    Code:
    ''''''''''''''''''''''''''''''''''
    'CProgressBar                    '
    'Made by Joacim Andersson 2000   '
    '[email protected]           '
    ''''''''''''''''''''''''''''''''''
    Option Explicit
    
    Private m_PicBox As PictureBox
    Private m_blnInit As Boolean
    Private m_Min As Long
    Private m_Max As Long
    Private m_Value As Long
    
    Public Sub Reset()
        Me.Value = m_Min
    End Sub
    
    Public Sub Tick()
        Me.Value = m_Value + 1
    End Sub
    
    Public Sub Init(PicBox As PictureBox)
        Set m_PicBox = PicBox
        m_PicBox.AutoRedraw = True
        m_blnInit = True
    End Sub
    
    Public Property Let Min(NewValue As Long)
        If NewValue >= m_Max Then
            Err.Raise 380, "<<Let>> CProgressBar::Min", "Invalid property value."
            Exit Property
        End If
        m_Min = NewValue
    End Property
    
    Public Property Get Min() As Long
        Min = m_Min
    End Property
    
    Public Property Let Max(NewValue As Long)
        If NewValue <= m_Min Then
            Err.Raise 380, "<<Let>> CProgressBar::Max", "Invalid property value."
            Exit Property
        End If
        m_Max = NewValue
    End Property
    
    Public Property Get Max() As Long
        Max = m_Max
    End Property
    
    Public Property Let Value(NewValue As Long)
        Dim eOldScaleMode As ScaleModeConstants
        Dim iOldScaleW As Long, iOldScaleH As Long
        If m_blnInit = False Then
            Err.Raise vbObjectError + 1124, "CProgressBar::Value", "Init hasn't been called."
            Exit Property
        End If
        If NewValue > m_Max Or NewValue < m_Min Then
            Err.Raise 380, "CProgressBar::Value", "Invalid property value."
            Exit Property
        End If
        m_Value = NewValue
        iOldScaleW = m_PicBox.ScaleWidth
        iOldScaleH = m_PicBox.ScaleHeight
        eOldScaleMode = m_PicBox.ScaleMode
        m_PicBox.ScaleMode = vbPixels
        With m_PicBox
            m_PicBox.Cls
            On Error Resume Next
            Err.Clear
            m_PicBox.Line (1, 1)-((.ScaleWidth - 2) * (CDbl(m_Value) / CDbl(m_Max)), .ScaleHeight - 2), .ForeColor, BF
            If Err Then
                m_PicBox.Line (0, 0)-(.ScaleWidth * (CDbl(m_Value) / CDbl(m_Max)), .ScaleHeight), .ForeColor, BF
            End If
        End With
        With m_PicBox
            .ScaleMode = eOldScaleMode
            .ScaleWidth = iOldScaleW
            .ScaleHeight = iOldScaleH
        End With
    End Property
    
    Public Property Get Value() As Long
        Value = m_Value
    End Property
    
    Private Sub Class_Initialize()
        m_Min = 0
        m_Max = 100
        m_Value = 0
    End Sub
    To try it out open a new Standard Exe project and add a class module. Copy and paste the code in to the class module and name it CProgressBar.
    Add a PictureBox to the form and set it's ForeColor property to whatever color you would like the Progress to show.
    Now add a Timer and copy the following code in to the form:
    Code:
    Option Explicit
    
    Private prbProgress As CProgressBar
    
    Private Sub Form_Load()
        Set prbProgress = New CProgressBar
        With CProgressBar
            .Init Picture1
            .Min = 0
            .Max = 100
        End With
    End Sub
    
    Private Sub Timer1_Timer()
        On Error Resume Next
        With prbProgress
            .Tick 'you can also increase the Value property
            If Err Then
                .Reset 'Begin again
            End If
        End With
    End Sub
    Best regards

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Nice but...

    a few things you forgot to do or typed wrong..

    You have to name the Class module: cProgressbar
    and int the Form load event:
    Code:
    With CProgressBar
    'needs to be
    With prbProgress
    then set the Timer interval to whatever to see it work.

    Very nice work!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224

    Wink

    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width