2013-07-20 117 views
-2

我將如何創建格式爲mm倒計時:用以下數據SS:創建倒計時(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 我試圖讓短期和短期工作,但目前只有seccount將工作

回答

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持有倒計時值

0

您的mincount變量被定義和初始化在您的計時器例程中,不會被更改,然後再次將它與原始值進行比較。

您可能想要考慮這一點:而不是圍繞兩個遞減值 - 分鐘和秒 - 來設置您的初始secCount爲60 *分鐘並將其計數。在您的間隔例程中,顯示​​secCount/60secCount % 60分鐘和秒。

+0

沒關係問題解決了。謝謝你的建議 –

+1

解決了,怎麼樣?這可以幫助其他人。 – usr2564301

+0

@OliverHands:如果您的問題現在已解決,並且此答案有助於解決問題,請考慮接受和/或加註此答案。如果你必須自己做一些研究,你可以把它作爲一個單獨的答案發布。 SO的一個常見做法是將任何人試圖幫助你的信譽歸功於此。因此,如果您使用上述答案來提出解決方案,請考慮接受和/或提升解決方案,儘管它可能沒有完全解決您的問題。 – Neolisk