将分钟添加到现有倒数计时器

时间:2014-12-03 09:41:21

标签: vb.net

如何在现有的倒数计时器中添加分钟,就像计时器倒计时一样我只需按一下按钮就可以增加10分钟,所以如果显示的时间是9.59,只需按一下按钮,时间就会增加显示19.59并继续倒计时

公共类TIMER

Private alarmtime As Date
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    If alarmtime < Date.Now Then
        Me.Timer1.Stop()
        MessageBox.Show("Time up")
    Else
        Dim remainingtime As TimeSpan = Me.alarmtime.Subtract(Date.Now)
        Me.Label1.Text = String.Format("{0}:{1:d2}:{2:d2}", _
        remainingtime.Hours, _
        remainingtime.Minutes, _
        remainingtime.Seconds)
    End If

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If RadioButton1.Checked = True Then
        Me.alarmtime = Date.Now.AddHours(TextBox1.Text)
        Me.Timer1.Start()
    ElseIf RadioButton2.Checked = True Then
        Me.alarmtime = Date.Now.AddMinutes(TextBox1.Text)
        Me.Timer1.Start()
    ElseIf RadioButton3.Checked = True Then
        Me.alarmtime = Date.Now.AddSeconds(TextBox1.Text)
        Me.Timer1.Start()
    End If
End Sub

Private Sub GameTIMER_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

结束班

它只是一个基本的倒数计时器它工作正常所有我需要做的是在它倒计时添加分钟,因为当计时器启动时我必须单击数字中的文本框类型然后按确定然后计时器开始,所以在文本框中关闭扭曲我只想按一个按钮,倒数计时器自动添加让我们说10分钟到当前时间显示,而倒计时

1 个答案:

答案 0 :(得分:0)

如果您正在谈论正常的计时器,那么这应该是您的答案:

Me.Timer1.Interval += (60000 * 10)

修改

首先尝试停止它:

Me.Timer1.Stop()
Me.Timer1.Interval += (60000 * 10)
Me.Timer1.Start()