如何制作我的计时器hh:mm:ss格式? [英] How to make my timer hh:mm:ss format?

查看:71
本文介绍了如何制作我的计时器hh:mm:ss格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的计时器看起来很好,但我想用hh:mm:ss格式



我目前的输出:



1:1:1



i想让它像

01:01:01



我的尝试:



my timer looks fine but i want to make it in hh:mm:ss format

my current output:

1:1:1

i want to make it like
01:01:01

What I have tried:

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    Label17.Text = "" & Label14.Text & ":" & Label16.Text & ":" & Label15.Text
    Label15.Text = Val(Label15.Text) + Val(1)
    If Label15.Text = 60 Then
        Label16.Text = Val(Label16.Text) + Val(1)
        Label15.Text = 0
    ElseIf Label16.Text = 60 Then
        Label14.Text = Val(Label14.Text) + Val(1)
        Label16.Text = 0
    End If

End Sub

推荐答案

计时器没有格式,它只是一个定时器,可以按期望的间隔引发Tick事件。您似乎从另一个标签格式化值,并且可能它们包含数字。如果是这样,那么您可以通过将数字转换为数字然后格式化来格式化文本中的数字。例如



Timer doesn't have a format, it's just a timer that raises Tick event on desired intervals. You seem to format the values from another labels and presumably they contain numbers. If that is true then you can format the number in the text by converting it to number and then formatting. For example

Label17.Text = "" & CInt(Label14.Text).ToString("00") & ":" & CInt(Label16.Text).ToString("00") & ":" & CInt(Label15.Text).ToString("00")





但是,请记住,如果标签包含除整数之外的其他内容,则上述代码将失败。



作为旁注,您应该为对象使用有意义的名称。这有助于理解和维护代码。



However, keep in mind that the code above will fail if the label contains anything else than an integer.

As a side note, you should use meaningful names for the objects. This helps to understand and maintain the code.


是的我已经修改了格式







小时= Label14.Text

分钟= Label16.Text

秒= Label15.Text



Label17.Text = hours.ToString(00)+:+ minutes.ToString(00)+:+ seconds.ToString(00)



Label15.Text = Val(Label15.Text)+ Val(1)

如果Label15.Text = 60那么

Label16 .Text = Val(Label16.Text)+ Val(1)

Label15.Text = 0

ElseIf Label16.Text = 60然后

Label14.Text = Val(Label14.Text)+ Val(1)

Label16.Text = 0

结束如果







但无论如何,感谢关注mika:)
yup i've already fixed the format



hours = Label14.Text
minutes = Label16.Text
seconds = Label15.Text

Label17.Text = hours.ToString("00") + ":" + minutes.ToString("00") + ":" + seconds.ToString("00")

Label15.Text = Val(Label15.Text) + Val(1)
If Label15.Text = 60 Then
Label16.Text = Val(Label16.Text) + Val(1)
Label15.Text = 0
ElseIf Label16.Text = 60 Then
Label14.Text = Val(Label14.Text) + Val(1)
Label16.Text = 0
End If



but anyway, thanks for concern mika :)


这篇关于如何制作我的计时器hh:mm:ss格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆