G
Grahmmer
I have a few timers that are added to a form at runtime. I can handle the
event fine, but I cannot identify which timer fired. Is there a way to do
this?
Timer Creation:
-------------
....some code...
Dim usersTimers(4) As System.Windows.Forms.Timer
For i = 0 To 4
'Build timer
usersTimers(i) = New System.Windows.Forms.Timer
With usersTimers(i)
'.name = "Timer" & Format(i, "00") - No NAME property on dynamic timer.
.Interval = Rand(5000) + 5000 'Five second + random amount
.Start()
End With
AddHandler usersTimers(i).Tick, AddressOf timTick
Next i
....more code...
Timer Event Handler:
-------------------
Protected Sub timTick(ByVal sender As System.Object, ByVal e As
System.EventArgs)
'Timer ticked. Handle it!
'MsgBox(sender.name) - No NAME property on a dynamic timer. How to ID?
MsgBox(sender.ToString)
End Sub
Timers don't get added to forms, so you can identify the control the
contains the timer. There is no TAG property on the timer. The only value
that I can seem to identify from the timer is it's interval. The above code
shows "[System.Windows.Forms.Timer], Interval: 100"
P.s. RAND() function generates a random integer between 0 and value,
inclusive.
event fine, but I cannot identify which timer fired. Is there a way to do
this?
Timer Creation:
-------------
....some code...
Dim usersTimers(4) As System.Windows.Forms.Timer
For i = 0 To 4
'Build timer
usersTimers(i) = New System.Windows.Forms.Timer
With usersTimers(i)
'.name = "Timer" & Format(i, "00") - No NAME property on dynamic timer.
.Interval = Rand(5000) + 5000 'Five second + random amount
.Start()
End With
AddHandler usersTimers(i).Tick, AddressOf timTick
Next i
....more code...
Timer Event Handler:
-------------------
Protected Sub timTick(ByVal sender As System.Object, ByVal e As
System.EventArgs)
'Timer ticked. Handle it!
'MsgBox(sender.name) - No NAME property on a dynamic timer. How to ID?
MsgBox(sender.ToString)
End Sub
Timers don't get added to forms, so you can identify the control the
contains the timer. There is no TAG property on the timer. The only value
that I can seem to identify from the timer is it's interval. The above code
shows "[System.Windows.Forms.Timer], Interval: 100"
P.s. RAND() function generates a random integer between 0 and value,
inclusive.