我有一个图片框(" piturebox1")和一张带有四张图片的图片列表(" imagelist1")。我希望这些每2秒随机更改一次,我不希望同一张图片连续出现两次。
我目前的代码是:
Dim Pic As Integer
Dim rand As New Random
Pic = rand.Next(0, ImageList1.Images.Count)
PictureBox1.Image = ImageList1.Images(Pic)
答案 0 :(得分:1)
由于你只有四张照片,而洗牌而不是随机选择通常是这类问题的首选解决方案,如果你想要显示超过8秒的图片,这对你不会有太大帮助。在这种特殊情况下,您可能最好只选择不是当前图片的随机图片:
' do not repeat this part....
Dim Pic As Integer = -1, LastSelected As Integer = -1
Dim rand As New Random
While Pic = LastSelected
Pic = rand.Next(0, ImageList1.Images.Count)
Loop
PictureBox1.Image = ImageList1.Images(Pic)
' Wait for 2 seconds, rinse, repeat