VB.NET如何为定时器间隔添加TimeSpan
VB.NET How to Add TimeSpan for Timer Inteval
这是场景,我有三个 NumericUpDown
用于秒、分和小时的值,如果在 NumericUpDown
中输入数字,即 5
,它将转换为 5000 ms
所以我的 Timer
可以读为 5 秒。我正在尝试为每个时间间隔制作一个调度程序,这是我的代码:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label13.Text = TimeSpan.FromSeconds(Form3.NumericUpDown1.Text).TotalMilliseconds
Label14.Text = TimeSpan.FromMinutes(Form3.NumericUpDown2.Text).TotalSeconds
Label15.Text = TimeSpan.FromHours(Form3.NumericUpDown3.Text).TotalMinutes
Dim times() As String = {Label13.Text, Label14.Text, Label15.Text}
For Each time In times
Dim interval As TimeSpan = TimeSpan.Parse(time)
Timer1.Interval = interval
MsgBox("hey")
Next
End Sub
它在 Timer1.Interval = interval
处出现错误 Timespan cannot be converted to Integer
,我想不出任何解决方法,你能帮帮我吗? TIA~!
这里有一些方法可以帮助您克服当前的错误。
Dim tsTest As TimeSpan = TimeSpan.FromSeconds(NumericUpDownTest.Value)
Label1.Text = tsTest.TotalSeconds.ToString("n0")
Timer1.Interval = CInt(tsTest.TotalMilliseconds)
从几秒钟开始,当该代码起作用时,看看您是否可以添加其他代码。
试试这个
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Stop()
Timer1.Interval = New TimeSpan(0, 0, CInt(nudMinutes.Value), CInt(nudSeconds.Value), CInt(nudMilliseconds.Value)).TotalMilliseconds
Timer1.Start()
End Sub
这是场景,我有三个 NumericUpDown
用于秒、分和小时的值,如果在 NumericUpDown
中输入数字,即 5
,它将转换为 5000 ms
所以我的 Timer
可以读为 5 秒。我正在尝试为每个时间间隔制作一个调度程序,这是我的代码:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label13.Text = TimeSpan.FromSeconds(Form3.NumericUpDown1.Text).TotalMilliseconds
Label14.Text = TimeSpan.FromMinutes(Form3.NumericUpDown2.Text).TotalSeconds
Label15.Text = TimeSpan.FromHours(Form3.NumericUpDown3.Text).TotalMinutes
Dim times() As String = {Label13.Text, Label14.Text, Label15.Text}
For Each time In times
Dim interval As TimeSpan = TimeSpan.Parse(time)
Timer1.Interval = interval
MsgBox("hey")
Next
End Sub
它在 Timer1.Interval = interval
处出现错误 Timespan cannot be converted to Integer
,我想不出任何解决方法,你能帮帮我吗? TIA~!
这里有一些方法可以帮助您克服当前的错误。
Dim tsTest As TimeSpan = TimeSpan.FromSeconds(NumericUpDownTest.Value)
Label1.Text = tsTest.TotalSeconds.ToString("n0")
Timer1.Interval = CInt(tsTest.TotalMilliseconds)
从几秒钟开始,当该代码起作用时,看看您是否可以添加其他代码。
试试这个
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Timer1.Stop()
Timer1.Interval = New TimeSpan(0, 0, CInt(nudMinutes.Value), CInt(nudSeconds.Value), CInt(nudMilliseconds.Value)).TotalMilliseconds
Timer1.Start()
End Sub