如何在计时器(分钟秒)WPF vb.net中显示timerformat

时间:2016-09-02 14:12:55

标签: wpf vb.net windows web timer

我有一个计时器,我想显示分钟和秒。我的计时器上升,当有60秒时,应该有一分钟,并且秒必须为空。现在它只是以秒为单位计算。我希望得到你的帮助。

Private timer As DispatcherTimer
Private CountUp As Integer

Public Sub DispatcherTimerSetup()

    timer = New DispatcherTimer()
    timer.Interval = New TimeSpan(0, 0, 1)
    AddHandler timer.Tick, AddressOf timer_Tick
    timer.Start()

End Sub

Private Sub timer_Tick(sender As Object, e As Object)

    CountUp += 1
    txblCountdown.Text = CountUp.ToString("00\:00")
    'timeformat

End Sub

最好的问候, 和Polina

1 个答案:

答案 0 :(得分:1)

您可以使用TimeSpan执行此操作。

Private Sub timer_Tick(sender As Object, e As Object)

    CountUp += 1
    Dim counter As TimeSpan
    counter = TimeSpan.FromSeconds(CountUp)
    txblCountdown.Text = counter.ToString("mm\:ss")

End Sub