Timers

I want to have a timer count to a certain time

so l want it to count to 20 and every second it counts it make the progress bar move.



Answer this question

Timers

  • rewan

    Drop a timer control and progressbar onto the form, with a couple of buttons and the following code will do what you want.

    Public Class Form1
    Private ICounterCount As Integer = 0

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Timer1.Interval = 1000
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    ICounterCount = 0
    ProgressBar1.Visible = True
    Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    ICounterCount = ICounterCount + 1
    ProgressBar1.Value = (100 / 20) * ICounterCount '//Percentage

    If ICounterCount = 20 Then
    Timer1.Stop()
    ProgressBar1.Visible = False
    End If
    End Sub
    End Class


  • Timers