在vb.net中的12,11,10,9,8到12,11,10,90,08

Leo*_*Lee 1 vb.net

计时器倒计时如14,13,12,11,10,9我想知道怎么能倒数9到09,所以它会像11,10,90,07,07 - 00,我我试过瞪眼,但我不准确搜索关键词

我的代码定时器

        Timer1.Interval = 1000
    If hours_label.Text = "" Then
        hours_label.Text = "0"
    End If
    If minutes_label.Text = "" Then
        minutes_label.Text = "0"
    End If
    If seconds_label.Text = "" Then
        seconds_label.Text = "0"
    End If
    If hours_label.Text = "00" Then
        hours_label.Text = "0"
    End If
    If minutes_label.Text = "00" Then
        minutes_label.Text = "0"
    End If
    If seconds_label.Text = "00" Then
        seconds_label.Text = "0"
    End If
    If seconds_label.Text > "0" Then
        seconds_label.Text = seconds_label.Text - 1
    End If
    If minutes_label.Text > "0" Then
        If seconds_label.Text = "0" Then
            minutes_label.Text = minutes_label.Text - 1
            seconds_label.Text = "59"
        End If
    End If
    If hours_label.Text > "0" Then
        If minutes_label.Text = "0" Then
            If seconds_label.Text = "0" Then
                hours_label.Text = hours_label.Text - 1
                minutes_label.Text = "59"
                seconds_label.Text = "59"
            End If
        End If
    End If
    If hours_label.Text = "0" Then
        If minutes_label.Text = "0" Then
            If seconds_label.Text = "0" Then
                Timer1.Enabled = False
                msgbox("Times Up")
                Screen_Locker.Show()
                Me.Close()
            End If
        End If
    End If
Run Code Online (Sandbox Code Playgroud)

提前感谢您的回答

cod*_*biz 8

这应该给你一个先发制人:使用PadLeft功能

Dim i As Integer = 15
While i >= 0
    Console.WriteLine(i.ToString().PadLeft(2, "0"c))
    i = i - 1
End While
Run Code Online (Sandbox Code Playgroud)

它是如何工作的:如果值是2位数,例如14,它保持不变但是如果它是1位数,则在它之前附加"0"使其成为2位数字(带2个字符的字符串)

12 = 12
11 = 11
10 = 10
 9 = 09
...
 0 = 00
Run Code Online (Sandbox Code Playgroud)