1

我有 StopWatch ,我希望秒表从01:00:12,000
我的代码开始计数(不起作用):

    Dim sp As New Stopwatch
    Dim lb As New Label
    Me.Controls.Add(lb)
    lb.Text = ""
    sp.Elapsed.Hours.Equals(1)
    sp.Elapsed.Minutes.Equals(0)
    sp.Elapsed.Seconds.Equals(12)
    sp.Elapsed.Milliseconds.Equals(0)
    sp.Start()
    lb.Text = sp.Elapsed.Hours.ToString & ":" & sp.Elapsed.Minutes.ToString & ":" & sp.Elapsed.Seconds.ToString & "," & sp.Elapsed.Milliseconds.ToString
4

2 回答 2

2

这是不可能的。

没有办法将Stopwatch类初始化为 0。

不过,没有什么能阻止您在结果中增加1 小时 12 秒。

lb.Text = (sp.Elapsed.Hours + 1).ToString & ":" & sp.Elapsed.Minutes.ToString _
          & ":" & (sp.Elapsed.Seconds + 12).ToString & "," _
          & sp.Elapsed.Milliseconds.ToString
于 2012-07-18T21:05:29.547 回答
0

秒表不是这样工作的。您需要做的是在不同的变量中记录开始时间,然后将秒表的经过时间添加到开始时间

Dim StartTime AS Date = Date.Now
...

Dim EndTime AS Date = StartTime.AddMilliseconds(StopWatch1.ElapsedMilliseconds)
于 2012-07-18T21:06:56.003 回答