每隔一定时间必须执行的方法也应该放在
Timer1_Tick
事件上。这是一个小的实现尝试一下,看看它是否可以相应地调整您的代码:
设置所需的 Timer 属性:
单击设计视图上的计时器及其属性框列表集:
- 30000 上的间隔属性(事件将每 30 秒触发一次)
- 启用 True(加载表单后计时器将开始工作)
然后在你的代码隐藏
private void ShowMessage()
{
MessageBox.Show("Hello Timer");
}
private void timer1_Tick(object sender, EventArgs e)
{
ShowMessage();
}
根据您发布的代码,这里还有一个工作实现,至于我从您的代码中理解的内容,您希望浏览器每隔特定秒刷新一次,并且数字上下控件显示在boatId 上设置的变量的值,这段代码是这样做的:
在它的“属性”框中设置数字上下控件的最小和最大属性(右键单击设计视图中的控件并搜索这两个属性)
然后尝试以下操作;
Public boatid As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.lblDate.Text = Now.ToString()
''Set a bigger winform to show the browser page better
Me.Width = 800
Me.Height = 600
googlemaps()
End Sub
''The browser will be refreshed every n seconds) according to what you have set on interval property of the timer control
Sub googlemaps()
Dim url As String = "http://www.google.com"
Me.WebBrowser1.Navigate(New Uri(url))
End Sub
''Loop over this method using the Tick event, while doing that verify the value
''of the boatid variable and if its less than the maximun value allowed by the numeric
''updown control increment it in one unit, then show it on the numeric selected value
''as well on the label control
Private Sub ChangeBoatIdValueCycling()
If boatid < 10 Then
boatid += 1
Else
boatid = 1
End If
Me.NumericUpDown1.Value = boatid
Me.lblBoatId.Text = boatid.ToString()
End Sub
''This wil show the id on the label text when you click up and down the numeric control
Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.lblBoatId.Text = Me.NumericUpDown1.Value.ToString()
End Sub
''This will set a variable with value 5 that will get shown selected on the numeric
''control as well as visible on the label text, the value will be shown because
''it exists in the range of 1 to 10 that is your requeriment.
Private Sub btnsequence_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsequence.Click
Dim i As Integer = 5
boatid = i
Me.NumericUpDown1.Value = boatid
Me.lblBoatId.Text = boatid.ToString()
End Sub
''Needed to repeat the form refresh and boatid cycling every n seconds according to your Interval property
''value
Private Sub RefreshTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RefreshTimer.Tick
googlemaps()
ChangeBoatIdValueCycling()
End Sub
我希望它有所帮助。让我知道事情的后续。