Hello,
I want to know if it's possible to see the current value of the timer enable. I want to click on a button and that shows me the time value of the timer.
Thanks
Printable View
Hello,
I want to know if it's possible to see the current value of the timer enable. I want to click on a button and that shows me the time value of the timer.
Thanks
Hi,Quote:
Originally Posted by jonnycage
You can try this;
Wkr,Code:TextBox1.Text = Timer1.Interval
sparrow1
Hi,
sparrow1 that just return to me the value of the interval that i've set.
For example:
timer.interval=3000
That code that you gave me returns 3000 and i want the current value of the timer , for example: current_timer:1565
If you want the number of elapsed ticks, use the tick event;
When the button is clicked, display the value of Inc. The duration will have been Inc*Interval seconds.Code:Dim Inc As Integer = 0
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Timer1.Tick
Inc += 1
End Sub
If you want real time as in time of day when the timer was accessed then do;
Code:Option Strict On
Public Class Form1
Dim CurrentTime As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim t As New System.Timers.Timer
t.Interval = 1000
t.Enabled = True
t.SynchronizingObject = Me
AddHandler t.Elapsed, AddressOf TimerState
Dim ShowTime As New Button
ShowTime.Text = "Show Time"
AddHandler ShowTime.Click, AddressOf ShowTimeClick
Me.Controls.Add(ShowTime)
End Sub
Public Sub TimerState(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
CurrentTime = e.SignalTime.ToString
End Sub
Private Sub ShowTimeClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show(CurrentTime)
End Sub
End Class
There is no such value associated with a Timer. If you want to calculate the time remaining until the next Tick event then it's up to you to have saved the current time on the last Tick and calculate it yourself. The easiest way would be to use a Stopwatch object and reset it each Tick. Note though that there Tick event handlers will not necessarily be executed exactly on the Interval.