Ocx progressbar sans fin paramétrable

Description

OCX d'une barre de progression sans fin à la Windows Update, que l'on peut paramétrer, couleur, vitesse, taille...
Ca fait longtemps que je voulais en faire une, donc j'ai décidé d'en faire profiter les autres.

Source / Exemple :


Option Explicit
'################################################################################################
                            'D E C L A R A T I O N S   D E S   E V E N E M E N T S
'################################################################################################
'Permet de réagir directement à une action réalisée sur le contrôles
Event Resize()   'Evènement qui ne requière aucun paramètre
'Récupère la couleur de fond du contrôle
Public Property Get BackColor() As Long
    BackColor = UserControl.BackColor
End Property
'Change la couleur de fond du contrôle
Public Property Let BackColor(ByVal NewColor As Long)
    UserControl.BackColor = NewColor
    PropertyChanged "BackColor" 'on indique le changement au programme
End Property
'Renvoi la couleur de la barre de progression
Public Property Get BarColor() As Long
    BarColor = C1.BackColor
End Property
'Change la couleur du curseur de la barre
Public Property Let BarColor(ByVal NewColor As Long)
    C1.BackColor = NewColor: C2.BackColor = NewColor: C3.BackColor = NewColor
    PropertyChanged "BarColor"
End Property
'Renvoi l'interval du timer
Public Property Get Interval() As Integer
    Interval = Timer.Interval
End Property
'Paramètrage de l'interval du timer
Public Property Let Interval(value As Integer)
    If ((value < 1) Or Not IsNumeric(value)) Then
        MsgBox "L'interval doit être un nombre positif!", vbExclamation
        value = 100
    End If
    Timer.Interval = value
End Property
'################################################################################################
'                       A C T I O N   P R I N C I P A L E   D E   L ' O C X
'################################################################################################
'Action exécutée à chaque mouvement du timer
Private Sub Timer_Timer()
    If C1.Left < (Label.Left + Label.Width) Then
        C1.Left = C1.Left + 10: C2.Left = C2.Left + 10: C3.Left = C3.Left + 10
    Else
        C1.Left = -460: C2.Left = -310: C3.Left = -160
    End If
End Sub
'################################################################################################
'       E N R E G I S T R E M E N T   E N   M E M O I R E   D E S   P R O P R I E T E S
'################################################################################################
'Permet de lire les propriétés lors du chargement du contrôle et affecter les valeurs par défaut
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    Label.BackColor = PropBag.ReadProperty("BackColor", vbWhite)
    C1.BackColor = PropBag.ReadProperty("BarColor", &HFF00&)
    C2.BackColor = PropBag.ReadProperty("BarColor", &HFF00&)
    C3.BackColor = PropBag.ReadProperty("BarColor", &HFF00&)
    Timer.Interval = PropBag.ReadProperty("Interval", 100)
End Sub
'Pour enregistrer les properties en mémoire
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Call PropBag.WriteProperty("BackColor", UserControl.BackColor, vbWhite)
    Call PropBag.WriteProperty("BarColor", C1.BackColor, &HFF00&)
    Call PropBag.WriteProperty("Interval", Timer.Interval, 100)
End Sub
'################################################################################################
'                                           M E T H O D E S
'################################################################################################
'Fonction appelée lors du redimmensionnement du control
Private Sub Usercontrol_Resize()
    Label.Width = UserControl.Width
    C1.Top = Label.Top + 30: C1.Left = Label.Left + 30:  C1.Height = Label.Height - 40
    C2.Top = Label.Top + 30: C2.Left = Label.Left + 180: C2.Height = Label.Height - 40
    C3.Top = Label.Top + 30: C3.Left = Label.Left + 330: C3.Height = Label.Height - 40
    RaiseEvent Resize
End Sub

Conclusion :


Code spécial débutant en OCX

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.