这是我在vb.net中的代码,用于使用计时器自动更改图像,但代码不起作用...
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.BackgroundImage = Image.FromFile("C:\images\\" + Label1.Text + "1.jpg")
Dim i As Integer = Convert.ToInt32(Label1.Text)
i += 1
If (i > 4) Then
i = 1
End If
Label1.Text = i.ToString()
End Sub
答案 0 :(得分:0)
将计数器移至班级。结合dbasnett的注释。此外,标签不应该反映当前的图像编号吗?你拥有它的方式标签中的值是背景图像的“前方”。
尝试更多类似的内容:
Private i As Integer = 1
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim FileName As String = "C:\images\" & i.ToString & ".jpg"
Try
Me.BackgroundImage = Image.FromFile(FileName)
Label1.Text = i.ToString()
i += 1
If (i > 4) Then
i = 1
End If
Catch ex As Exception
Debug.Print(FileName)
MessageBox.Show(FileName & vbCrLf & vbCrLf & ex.ToString, "Error Loading Image")
End Try
End Sub