我想通过按下按钮来更新 wpf 形式的文本块,并使用倒计时器。 目前看来我的 DispatcherTimer 的 tick 事件没有被调用。
这是我在 vb.net 中的全部代码
Private WithEvents tm5min As New DispatcherTimer
Private Sub BtnStart5_MouseDown(sender As Object, e As MouseButtonEventArgs) Handles BtnStart5.MouseDown
Try
tm5min.Interval = TimeSpan.FromMinutes(5)
tm5min.Start()
Debug.WriteLine("clock started with: " & tm5min.Interval.TotalMinutes)
Catch ex As Exception
Debug.Write(ex.Message)
End Try
End Sub
Private Sub tm5min_Tick(sender As Object, e As EventArgs) Handles tm5min.Tick
Debug.Write("I'm ticking")
TxtCountdown.Text = Date.Now.ToString("mm\:ss")
End Sub
使用当前代码使用鼠标右键触发事件。
否则
Private Sub btns_Click(sender As Object, e As RoutedEventArgs) Handles btns.Click Try tm5min.Interval = TimeSpan.FromSeconds(5) tm5min.Start() Debug.WriteLine("clock started with: " & tm5min.Interval.TotalMinutes) Catch ex As Exception Debug.Write(ex.Message) End Try End Sub