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.
Asked
Active
Viewed 53 times
-1
-
You're using Visual Basic or C#? – Rubio Jesús Jul 14 '22 at 13:39
-
estoy usando c# – Gonzalez Casillas Maria Isabel Jul 14 '22 at 13:39
-
1Does this answer your question? [How to reset a timer in C#?](https://stackoverflow.com/questions/1042312/how-to-reset-a-timer-in-c) – The2Step Jul 14 '22 at 13:46
-
I suspect you do not want to "reset the timer" but rather the variable where you store the current image index. But hard to tell without seeing any code. – Klaus Gütter Jul 14 '22 at 14:19
2 Answers
0
You can reset the timer using the code:
myTimer.stop();
myTimer.start();
Just change the [myTimer] to your timer's control name.
Also you could check up this documentation: Timer.stop

Rubio Jesús
- 105
- 1
- 9
-
Si lo restablece a 0 pero despues cambia al valor al que se que quedo anteriormente ejemplo, lo pause en 20, lo reinicio y me aparece 0, 21, 22, 23 y asi sucesivamente – Gonzalez Casillas Maria Isabel Jul 14 '22 at 13:57
-
Ya pude solucionarlo con la documentacion que me proporcionaste gracias – Gonzalez Casillas Maria Isabel Jul 14 '22 at 15:23
-
@GonzalezCasillasMariaIsabel You're welcome! if you could post the specific code line that solved your issue would be cool so any user searching for your same problem can see its solution. Also, consider marking the answer as accepted:) and don't forget you're in SO, you have to use english language. For spanish users there is [Stack overflow ES](https://es.stackoverflow.com/) – Rubio Jesús Jul 14 '22 at 15:26
-
Este es el extracto de codigo que soluciono mi duda: int timeleft = 1; private void timer1_Tick(object sender, EventArgs e) { if (timeleft > 0) { timeleft = timeleft + 1; label1.Text = timeleft + ""; } if (label1.Text == "40") { timeleft = 1; } } – Gonzalez Casillas Maria Isabel Jul 14 '22 at 15:29
0
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

dbasnett
- 11,334
- 2
- 25
- 33