Public Class Form1
    Private PicNo As Integer
    '定义成员变量PicNo，表示显示图片号 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PicNo = 0
        Timer1.Enabled = False     ' 设置定时器不可用
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '设置过滤器，只显示图像文件 
        OpenFileDialog1.Filter = "位图文件|*.bmp|GIF文件|*.gif|JPEG文件|*.jpg"
        ' 指定缺省过滤器（默认打开JPEG文件） 
        OpenFileDialog1.FilterIndex = 3
        OpenFileDialog1.ShowDialog() '显示“打开”对话框 
        ' 将用户选定文件载入列表框 
        ListBox1.Items.Add(OpenFileDialog1.FileName)
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Enabled = True      ' 设置定时器可用 
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ListBox1.SelectedIndex = PicNo
        Dim s As String
        s = ListBox1.SelectedItem.ToString() ' 得到某一要显示图片的路径
        PictureBox1.Image = Image.FromFile(s) ' 加载图片
        PicNo = PicNo + 1 ' 为得到下一张图片做准备
        If (PicNo >= ListBox1.Items.Count) Then
            '如果是最后一张，则转为第一张
            PicNo = 0
        End If
    End Sub
End Class
