Search code examples
c#formstimerreset

How can I make a timer return to its initial value and reflect in label?


I am working with C#. I have a pictureBox that every 30 seconds change its image. There are a total of 8 images but the problem is that when I finish changing all the images I don't know how to make the timer return to 0 and be reflected in a Label and start running the images again.


Solution

  • In VB

    Private ImgListPath As List(Of String) '8
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Static whPicIdx As Integer = 0
        Dim ct As Integer = ImgListPath.Count
        PictureBox1.Load(ImgListPath(whPicIdx))
        whPicIdx += 1
        If whPicIdx >= ct Then
            whPicIdx = 0
        End If
    End Sub