我想要创建一个变量,它可以在毫秒内从0计数--我不想使用工具箱中的计时器,而是用代码构建它。到目前为止,我已经声明了一个timer对象,但是如何将它绑定到一个可以将时间转换为计数器并将其附加到变量中的事件呢?
请看下面我迄今所做的尝试,但没有成功。
Imports System.Timers
Public Class Counter
Property Count As Integer
Private Sub Counter_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Count = Counter()
Console.WriteLine(Count)
End Sub
Public Function Counter() As Integer
' Create timer
Dim timer As Timer = New Timer()
timer.Interval = 1000
'AddHandler timer.Elapsed, AddressOf TimerEvent
timer.AutoReset = True
timer.Enabled = True
Return Integer.Parse(timer.ToString())
End Function
Private Sub CountEvent(ByVal source As Object, ByVal e As ElapsedEventArgs)
'Console.WriteLine("Event Raised at {0:HH:mm:ss.fff}", e.SignalTime)
'Console.WriteLine("Count Miliseconds {0:fff}", e.SignalTime) ' count milisecond
Console.WriteLine("Count Seconds {0:ss}", e.SignalTime) ' count milisecond
End Sub
End Class发布于 2022-06-27 10:57:18
我解决了
暗计数器为整数
Private Sub TimerEvent(ByVal source As Object, ByVal e As ElapsedEventArgs)
' Count Up
If 1 <> 2 Then
Counter = Counter + 1
End If
Console.WriteLine("Count Up: " & Counter)
End Subhttps://stackoverflow.com/questions/72763453
复制相似问题