我想在 Windows 窗体上的标签控件上显示经过的时间。为此,我正在使用 System.Timers.timer 但无法使用按钮单击事件的经过时间来更新标签。
例如
Private Shared mtimer As System.Timers.Timer
Private Sub btnprocess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprocess.Click
'Counter to Calculate time as Process Starts
mDate = Date.Now
''Create a timer with second interval
mtimer = New System.Timers.Timer()
''Hook the Elapsed event
**AddHandler mtimer.Elapsed, AddressOf Processtick**
mtimer.Start()
'set the interval 1 second
mtimer.Interval = 1000
mtimer.Enabled = True
''Some functions
end sub
Private Sub Processtick(ByVal source As Object, ByVal e As ElapsedEventArgs)
Dim ts As TimeSpan = DateTime.Now.Subtract(mDate)
lblelapsed.Text = ts.Hours & ":" & ts.Minutes & ":" & ts.Seconds
End sub
尝试了上面的代码,但它不起作用,我想在用户单击“处理”按钮后立即更新标签控件上的经过时间,
直到所有功能在按钮单击时执行。
请帮忙。