Advertisement
1_2002 Graphics #109828

A custom progressbar class module - Updated

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.

AI

Resumo por IA: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Código fonte
original-source
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)
PicBar.Cls
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
Else
  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
PicBar.Refresh
End Sub

'USE LIKE THIS:
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!!!!!!!!!!!!!!!!!!!!!!!!!!!
Comentários originais (3)
Recuperado do Wayback Machine