如何使用以下数据创建mm:ss格式的倒计时:
Dim secCount As String = 0
Dim button1 As Decimal
Private Sub button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button.Click
button1 = InputBox("Set button1 for how many minutes?", "button1", "5")
If Timer1.Enabled = True Then
Timer1.Enabled = False
Else
secCount = 60
Timer1.Interval = 1000
Timer1.Enabled = True
Timer1.Start()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim mincount As String = button1
secCount = secCount - 1
If secCount = "-1" Then
secCount = "59"
End If
If mincount = button1 Then
secCount = secCount.PadLeft(2, "0"c)
Label6.Text = (mincount + ":" + secCount)
If secCount = button1 Then
MsgBox("button1")
End If
End Sub
标签持有倒计时mm:ss 我试图让mincount和seccount工作,但目前只有seccount才能工作
答案 0 :(得分:0)
您的mincount
变量在您的计时器例程中被定义和初始化,不会被更改,然后您再次将其与原始值进行比较。
您可能需要考虑这一点:而不是在两个递减值(分钟和秒)之间徘徊,将初始secCount设置为60 *分钟并将其计算下来。在您的间隔例程中,显示secCount/60
和secCount % 60
分钟和秒。
答案 1 :(得分:0)
Dim selfdestruct1 As Decimal
Dim mincount As String
Dim secCount As String = 0
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Selfdestruct.Click
Dim wholepart As Decimal
Dim fractionpart As Decimal
If Timer1.Enabled = True Then
Timer1.Enabled = False
MsgBox("button has been cancelled")
Console.WriteLine("button has been cancelled")
Label6.Visible = False
Else
button1 = InputBox("Set button1 for how many minutes?", "BUTTON1", "5")
wholepart = Math.Truncate(button1)
fractionpart = button1 - wholepart
secCount = 60
Timer1.Interval = 1000
Timer1.Enabled = True
Timer1.Start()
Label6.Visible = True
End If
mincount = wholepart
secCount = fractionpart * 60
secCount = secCount.PadLeft(2, "0"c)
Label6.Text = (mincount + ":" + secCount)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
secCount = secCount - 1
If secCount = "-1" Then
secCount = "59"
mincount = mincount - 1
End If
secCount = secCount.PadLeft(2, "0"c)
Label6.Text = (mincount + ":" + secCount)
If mincount = 0 And secCount = 0 Then
MsgBox("YAY!")
End If
End Sub
label6保留倒计时值