每30秒自动刷新一次表格vb.net

时间:2018-11-07 15:11:25

标签: vb.net timer refresh

我想整天打开一个表单,但是我想每30秒自动刷新一次。 我正在使用此代码:

    Private Sub tempo(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim timer = New Timer
        timer.Interval = 30 * 1000
        AddHandler timer.Tick, AddressOf Form12_Load
        timer.Start()

    End Sub


    Private Sub Form12_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    ...
    End sub

但是它不起作用。你知道我在做什么错吗? 谢谢。

2 个答案:

答案 0 :(得分:0)

我的0.02,不需要太多解释:

Private WithEvents clock As New Timers.Timer

Private Sub Form12_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    With clock
        .Interval = 30000
        .AutoReset = True
        .Enabled = True
        .Start()
    End With
End Sub

Private Sub clock_tick() Handles clock.Elapsed
    Me.BeginInvoke(Sub()
                       Me.Refresh()
                   End Sub)
End Sub

答案 1 :(得分:-2)

嗨,您必须从tick-timer事件中调用form_load事件:

Private Sub Form12_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim timer = New Timer
    timer.Interval = 30 * 1000
    AddHandler timer.Tick, AddressOf timer_Tick
    timer.Start()
End sub
Private Sub timer_Tick(ByVal sender As Object, ByVal e As EventArgs)   
    Form12_Load(me,nothing)
End Sub