Vb.net VBS定时器时钟-输出标签

Vb.net VBS定时器时钟-输出标签,vb.net,visual-studio,Vb.net,Visual Studio,我需要在VisualStudioVBS中使用此代码的一些帮助,我不知道如何输出文本中的所有变量 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick Dim timer Dim timer2 Dim timer3 Dim finaltimer timer = (sec.Text + 1) timer = Format(timer, "00"

我需要在VisualStudioVBS中使用此代码的一些帮助,我不知道如何输出文本中的所有变量

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Dim timer
    Dim timer2
    Dim timer3
    Dim finaltimer
    timer = (sec.Text + 1)
    timer = Format(timer, "00")
    If timer = 60 Then
        timer = 0
        timer2 = (min.Text + 1)
        timer2 = Format(timer2, "00")
        If timer2 = 60 Then
            timer2 = 0
            timer3 = (hour.Text + 1)
            timer3 = Format(timer3, "00")
        End If
    End If
    finaltimer = timer & ":" & timer2 & ":" & timer3
    sec.Text = finaltimer
End Sub

以下是JMCILHINEY建议的秒表方法的一个简单示例:

Private SW As New Stopwatch

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    SW.Start()
    Timer1.Start()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Dim ts As TimeSpan = SW.Elapsed
    Label1.Text = ts.ToString("hh\:mm\:ss")
End Sub

如果
秒文本
预期类似于
“01:35:59”
,您希望如何向其添加1?谢谢,我现在已经看到了。。。现在我觉得自己有点傻了听起来你只是想跟踪一个开始时间(当“计时器”启动时),然后做一些类似的事情(我习惯VBA,所以在VB.Net中这不一定是相同的)
finaltimer=Format(现在()-startTime,“hh:mm:ss”)
如果要显示经过的时间,则应创建一个
秒表
并在
启动时启动
计时器
。在
Tick
事件处理程序中,然后从
Stopwatch
eassed
属性中获取
TimeSpan
,并调用其
ToString
方法,传递适当的格式说明符。这意味着用一行代码替换所有代码。而且,这绝对不是VBS(Visual Basic脚本)。您正在WinForms应用程序中使用VB.Net。