这是我的代码:
Private Sub StartToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartToolStripMenuItem.Click
Video1.Start()
Video1.Interval = 4000
ToolStripStatusLabel2.Text = "Browsing"
End Sub
Private Sub Video1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Video1.Tick
ToolStripStatusLabel4.Text += 1
ListBox1.SelectedIndex = rnd.Next(0, ListBox1.Items.Count - 1)
WebBrowser1.Navigate(ListBox1.SelectedItem)
End Sub
问题是可以说定时器间隔设置为4秒(4000)。我希望我的应用程序按顺序导航到ListBox中的每个项目:website1,website 2,website3等。但它改为:网站5,网站2,网站8,网站1.它导航到randome网站。
答案 0 :(得分:1)
它随机的原因似乎是因为您正在调用随机数生成器并从列表框中选择该项:
rnd.Next(0, ListBox1.Items.Count - 1)
相反,您应该分配一个变量来存储您当前所在的索引。每次计时器滴答时增加此值。
Private currentIndex As Integer = 0
Private Sub Video1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Video1.Tick
ToolStripStatusLabel4.Text += 1
currentIndex += 1
ListBox1.SelectedIndex = currentIndex
WebBrowser1.Navigate(ListBox1.SelectedItem)
End Sub