Search Tools Links Login

A custom progressbar class module - Updated

Visual Basic 6, or VB Classic

I created this class module to turn a picturebox into a progressbar. It is very simple right now. You can se the back and forecolor then set the value and (update) ! wether to show percent or not !. Please tell me what you think (and vote please) By the way. Most color combo's work. All the vb color constants do, u know vbblack, vb red so on. But if u usse long or hex values, they sometimes go different colors.

Original Author: Coding Genius

Side Effects

If you use hex or long values when setting the colors sometimes the oclors ocme out wrong because of the binary operators being used but all the vbcolorconstants work, vbblac, vbgreen, vbblue and so on. Most colors work.


Option Explicit
Private mvarValue As Integer
Private mvarForeColor As Long
Private mvarBackColor As Long
Private mvarDrawText As Boolean
Public Event ProgressDone()
Public Property Let BackColor(ByVal vData As Double)
  mvarBackColor = vData
End Property
Public Property Get BackColor() As Double
  mvarBackColor = BackColor
End Property
Public Property Let ForeColor(ByVal vData As Double)
  mvarForeColor = vData
End Property
Public Property Get ForeColor() As Double
  mvarForeColor = ForeColor
End Property
Public Property Let value(ByVal vData As Integer)
  mvarValue = vData
End Property
Public Property Get value() As Integer
  value = mvarValue
End Property
Public Property Get DrawText() As Boolean
  DrawText = mvarDrawText
End Property
Public Property Let DrawText(ByVal vData As Boolean)
  mvarDrawText = vData
End Property
Private Sub Class_Initialize()
  mvarValue = 0
  mvarBackColor = &H8000000F
  mvarForeColor = &HFF0000
  mvarDrawText = True
End Sub
Public Sub InitProgress(ByVal PicBar As PictureBox)
With PicBar
  .ScaleMode = vbPixels
  .AutoRedraw = True
  .FontBold = True
  .BackColor = mvarBackColor
  .ForeColor = mvarForeColor
End With
End Sub
Public Sub DrawStatus(ByVal PicBar As PictureBox)
If mvarDrawText Then
  PicBar.CurrentX = (PicBar.ScaleWidth / 2) - (PicBar.TextWidth(CInt((PicBar.TextWidth(mvarValue / PicBar.Width) * 100))) / 2)
  PicBar.CurrentY = (PicBar.ScaleHeight / 2) - (PicBar.TextHeight("1") / 2)
End If
If mvarValue >= PicBar.ScaleWidth Then
  RaiseEvent ProgressDone
  If mvarDrawText Then
   PicBar.Print "100%"
  End If
  If mvarDrawText Then
   PicBar.Print CStr(Round(((mvarValue / PicBar.ScaleWidth) * 100), 0) & "%")
  End If
End If
PicBar.Line (0, 0)-((mvarValue / PicBar.ScaleWidth) * PicBar.ScaleWidth, PicBar.ScaleHeight), mvarForeColor Xor mvarBackColor, BF
End Sub

Option Explicit
Private WithEvents progress As clsProgressBar
Private Sub Form_Load()
Set progress = New clsProgressBar
progress.BackColor = vblack
progress.ForeColor = vbGreen
progress.InitProgress Picture1
End Sub
Private Sub progress_ProgressDone()
Timer1.Enabled = False
MsgBox "done"
End Sub
Private Sub Timer1_Timer()
progress.value = progress.value + 10
progress.DrawStatus Picture1
End Sub
'Thats how you use it!!!!!!!!!!!!!!!!!!!!!!!!!!!

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 121 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.