-2

我将如何使用以下数据创建 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 可以工作

4

2 回答 2

0

您的mincount变量在您的计时器例程中被定义和初始化,不会被更改,然后您再次将其与原始值进行比较。

您可能需要考虑这一点:与其在两个递减值(分钟和秒)之间折腾,不如将初始 secCount 设置为 60*minutes 并将其倒数。在您的间隔例程中,显示secCount/60​​ 和secCount % 60分钟和秒。

于 2013-07-20T12:49:14.047 回答
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 保存倒计时值

于 2013-07-21T10:00:49.080 回答