Programmer progressbar, timer en vb

asdesas -  
Posotaz Messages postés 505 Statut Membre -
bjour à tous je voudrais savoir comment programmer un progressbar en vb je suis debutant merci
Configuration: Windows XP
Internet Explorer 6.0

1 réponse

  1. Posotaz Messages postés 505 Statut Membre 226
     
    Bonjour Asdesas,

    Au temps où j'étais jeune (et con -mais pas moins que maintenant :-D) j'apprenais aussi le VB et j'avais créé un petit programme pour faire croire aux gens qu'ils étaient infectés par un virus. Un écran qui "efface" le dique dur, qui indique à la fin que c'était juste une blague, qui cache l'application et ensuite après 10 secondes fait croire que c'est tout sauf une blague en affichant un autre écran.

    Pour ce faire j'ai utilisé un Timer et en guise de progress bar un simple label avec un fond jaune (et rouge quand il arrive au bout) auquel j'ajoute le caractère "_" tous les 10%. Je n'ai jamais utilisé d'autre composant Progress Bar, je ne sais plus si y'en a un par défaut en VB.

    Je te mets le code, fais-en ce que tu veux ;-) :

    PS : Si je me souviens bien, Timer1 est un composant Timer que j'avais déplacé depuis la barre d'outils, c'est pour ça que tu ne trouves pas la déclaration dans le code, ça se place graphiquement même si son usage est programmatique.
    VERSION 5.00
    Begin VB.Form Form1 
       BackColor       =   &H00FF0000&
       ClientHeight    =   4830
       ClientLeft      =   60
       ClientTop       =   60
       ClientWidth     =   6030
       ControlBox      =   0   'False
       LinkTopic       =   "Form1"
       ScaleHeight     =   4830
       ScaleWidth      =   6030
       ShowInTaskbar   =   0   'False
       StartUpPosition =   3  'Windows Default
       WindowState     =   2  'Maximized
       Begin VB.CommandButton Command3 
          Caption         =   "Sortie"
          Height          =   375
          Left            =   720
          TabIndex        =   3
          Top             =   3840
          Visible         =   0   'False
          Width           =   735
       End
       Begin VB.Timer Timer1 
          Enabled         =   0   'False
          Interval        =   1000
          Left            =   4320
          Top             =   3720
       End
       Begin VB.Label Label3 
          AutoSize        =   -1  'True
          BackColor       =   &H00C0FFFF&
          BeginProperty Font 
             Name            =   "Courier New"
             Size            =   20.25
             Charset         =   178
             Weight          =   700
             Underline       =   0   'False
             Italic          =   0   'False
             Strikethrough   =   0   'False
          EndProperty
          Height          =   465
          Left            =   1080
          TabIndex        =   2
          Top             =   2640
          Width           =   240
       End
       Begin VB.Label Label2 
          BackColor       =   &H00FF0000&
          Caption         =   "Effacement du disque dur : "
          BeginProperty Font 
             Name            =   "Courier New"
             Size            =   14.25
             Charset         =   0
             Weight          =   700
             Underline       =   0   'False
             Italic          =   0   'False
             Strikethrough   =   0   'False
          EndProperty
          ForeColor       =   &H00C0E0FF&
          Height          =   855
          Left            =   1080
          TabIndex        =   1
          Top             =   1560
          Width           =   3975
       End
       Begin VB.Label Label1 
          BackColor       =   &H00FF0000&
          Caption         =   "Blue Kill :: AH  AH  AH...."
          BeginProperty Font 
             Name            =   "Courier New"
             Size            =   14.25
             Charset         =   0
             Weight          =   700
             Underline       =   0   'False
             Italic          =   0   'False
             Strikethrough   =   0   'False
          EndProperty
          ForeColor       =   &H00FFFFFF&
          Height          =   615
          Left            =   600
          TabIndex        =   0
          Top             =   720
          Width           =   4935
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Option Explicit
    Dim pc As Integer, barre As Integer
    
    Private Sub Command3_Click()
        Me.Hide
        MsgBox "Mais oui, c'était vraiment une blague!!", vbOKOnly, "LOL"
        Load Form2
        Unload Me
    End Sub
    
    Private Sub Form_Load()
        Dim nomUser As String
        Dim ret As Long
        Dim longBuff As Long
        pc = 0
        barre = 0
        nomUser = Space(255)
        longBuff = 255
        ret = Module1.GetUserName(nomUser, longBuff)
        MsgBox "Message personnel pour " & RTrim(nomUser) & ":", vbOKOnly, "Ah ah ah..."
        MsgBox "Félicitations!!!" & vbLf & vbLf & "Vous venez d'être infecté par le virus BlueKill!!!", vbOKOnly, "Ah ah ah!!!"
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
        Dim reste As Integer
        If (pc <= 100) Then
            Label2.Caption = "Effacement du disque dur : " & pc & "% effectués."
            reste = Int(pc / 10)
            If (reste > barre) Then
                barre = reste
                Label3.Caption = Label3.Caption & "_"
            End If
            If (pc > 91 And pc < 98) Then
                Timer1.Interval = 5000
                pc = pc + 3
            Else
                pc = pc + 2
            End If
        Else
            Timer1.Enabled = False
            Label3.BackColor = &HFF&
            Command3.Visible = True
        End If
    End Sub
    
    
    0