Using
Thread.Sleep
causes the UI thread to freeze. It cannot process any messages, which means it cannot repaint itself to show the selected image.
Use a
Timer
to update your images instead of a loop:
Timer Class (System.Windows.Forms) | Microsoft Docs[
^]
Private picNum As Integer
Private picTimer As System.Windows.Forms.Timer
Private Sub ShowCurrentPicture()
mainpbx1.ImageLocation = "F:\Programs\TV\" & picNum & ".jpg"
End Sub
Private Sub ShowNextPicture()
picNum = picNum + 1
ShowCurrentPicture()
If picNum = 4 Then
picTimer.Enabled = False
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If picTimer Is Nothing Then
picTimer = New System.Windows.Forms.Timer()
AddHandler picTimer.Tick, AddressOf ShowNextPicture
picTimer.Interval = 10000
End If
If Not picTimer.Enabled Then
picNum = 1
ShowCurrentPicture()
picTimer.Enabled = True
End If
End Sub