我有一个间隔= 1的计时器
间隔1 = 1毫秒?
如果间隔1不是1毫秒,则告诉我哪个控制间隔= 1ms
代码:
Imports System.Globalization
Public Class Form1
'Default Time To Start From
Dim time As String = "00:00:00,000" 'Start From Here
'Label
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
Timer1.Start() 'Run The Timer On Click
End Sub
'TIMER
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Timer Interval = 1
Dim ci = CultureInfo.InvariantCulture
Dim original As TimeSpan = TimeSpan.ParseExact(time, "hh\:mm\:ss\,fff", ci) 'ParseExact
Dim difference As TimeSpan = TimeSpan.FromMilliseconds(1) ' = 1 Millisecond
Dim final = original
final = original + difference ' connect between original to difference !(00:00:00,000 + 1 MS = 00:00:00,001)!
Dim output As String = final.ToString("hh\:mm\:ss\,fff", ci) 'convert to the format ( = 00:00:00,001 ) (Back It To The Right Format)
time = output '!!Update!! the Time String from 00:00:00,000 To 00:00:00,001 |||| And in the Next Time 00:00:00,001 + 1 = 00:00:00,002
Label1.Text = time 'Show the Time String in the label
End Sub
End Class
如你所见 - 我正在使用常规计时器使用间隔1,但我认为这是因为计时器不计算毫秒数
如果你有建议,告诉我。
答案 0 :(得分:1)
来自MSDN的间隔属性的描述是:
获取或设置Tick事件之前的时间(以毫秒为单位) 相对于Tick事件的最后一次出现而提出。
但是(史蒂夫在评论中指出):
Windows窗体计时器组件是单线程的,并且是有限的 精度为55毫秒。如果您需要多线程 更精确的计时器,使用System.Timers中的Timer类 命名空间
取自http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx
此处描述了System.Timers.Timer
类:[{3}}
答案 1 :(得分:-1)
Imports System.Globalization
Public Class Form1
Dim time As String = "00:00:00:00"
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim ci = CultureInfo.InvariantCulture
Dim original As TimeSpan = TimeSpan.ParseExact(time, "dd\:hh\:mm\:ss", ci) 'ParseExact
Dim difference As TimeSpan = TimeSpan.FromSeconds(1) ' = 1 Millisecond
Dim final = original
final = original + difference ' connect between original to difference !(00:00:00,000 + 1 MS = 00:00:00,001)!
Dim output As String = final.ToString("dd\:hh\:mm\:ss", ci) 'convert to the format ( = 00:00:00,001 ) (Back It To The Right Format)
time = output '!!Update!! the Time String from 00:00:00,000 To 00:00:00,001 |||| And in the Next Time 00:00:00,001 + 1 = 00:00:00,002
Label1.Text = time 'Show the Time String in the label
End Sub
End Class
这是工作脚本。 IDK为什么有效,但它有效! :)