This time I want to show how to create a timer in visual basic. Net using the timer component.
Well, do not pretend that this is a step by step example showing each of the modified properties of each control, on the contrary, I want to concentrate on the functionality of the timer and I will let you design. Just show them that I did.
The controls used are: a form, three buttons and two labels. We also need to add a Timer to the form. It would look more or month as follows: 
But the first thing we will define four private variables at the level of form.
Private hours As Integer = 0 Private minutes As Integer = 0 Private second As Integer = 0 Private milliseconds As Integer = 0
The Timer component must have its interval property to 100.
We will create a function to display in label1 over time:
Sub printTime ()
Label1.Text = hora.ToString.PadLeft (2, "0") & ":"
Minuto.ToString.PadLeft Label1.Text & = (2, "0") & ":"
Segundo.ToString.PadLeft Label1.Text & = (2, "0") & ":"
Milisegundo.ToString.PadLeft Label1.Text & = (1, "0")
Label1.Refresh ()
End Sub
In the tick event of the Timer component is where you place all the logic of the stopwatch. Copy the following code there:
+ = 1 millisecond Then if millisecond = 9 millisecond = 0 second + = 1 If seconds = 59 Then second = 0 + = 1 minute Then If = 59 minutes minute = 0 hour + = 1 End If End If End If printTime ()
Well, what remains is the code of the three buttons. The start button activates the timer:
Timer1.Enabled = True
The Pause button stops the timer:
Timer1.Enabled = False
And the reset button to reset the values of the variables:
time = 0 minute = 0 second = 0 millisecond = 0 printTime ()
I hope that this example does not prove complicated and above all that will be useful. Finally I leave you a snapshot of the stopwatch is running: 
Information Bitacoras.com ...
Rate in Bitacoras.com: This time I want to show how to create a timer in visual basic. Net using the timer component. Well, do not pretend that this is a step by step example showing each of the modified properties of ...
Thank you very much I was just beginning with very useful. Net and well described.
Goodbye.
Examples are very good ... and thanks for contributing knowledge for q and q tiens recently started ...
Hello!
px thank you very much was a tremendous help your code is more served me save my life lol ...
not quite work thanks ...
bye bye kuidate ...
Thank you very much man ... without complications this example, very very good, that God will help you as ...
Very good contribution is so I congratulate you!
thank you very much helped me a lot
The timer is fine just not to the time after 59 seconds 00:01:59:0 not mind jumps from 58 to 00 and 59 does not exist, please check your own code
The solution would be so
+ = 1 millisecond
If Millisecond = 10 Then
Millisecond = 0
Second + = 1
If second = 60 Then
Second = 0
Minute + = 1
If Minute = 60 Then
Min = 0
Time + = 1
End If
End If
End If
PrintTime ()
Thus the second or minute 59 would exist but are grateful for the contribution.
Very good, thank you very much!! I got my I'm duranga
THANKS! I woke up the example logic xq make a mega project I hope to continue evaluating this example instance of this magnitude suviendo God bless
I am new to programming haci do my project.
Public Class Form1
Private hours As Integer = 0
Private minutes As Integer = 0
Private second As Integer = 0
Private milliseconds As Integer = 0
Sub printTime ()
Label1.Text = hora.ToString.PadLeft (2, "0") & ":"
Minuto.ToString.PadLeft Label1.Text & = (2, "0") & ":"
Segundo.ToString.PadLeft Label1.Text & = (2, "0") & ":"
Milisegundo.ToString.PadLeft Label1.Text & = (1, "0")
Label1.Refresh ()
End Sub
Timer1_Tick Private Sub (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
+ = 1 millisecond
Then if millisecond = 9
millisecond = 0
second + = 1
If seconds = 59 Then
second = 0
+ = 1 minute
Then If = 59 minutes
minute = 0
hour + = 1
End If
End If
End If
printTime ()
End Sub
Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
Private Sub Button2_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Enabled = False
End Sub
Button4_Click Private Sub (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
End
End Sub
Thank you very much for the contribution
Good code!
Good code .... I served to perfection above corrected the error .... thanks
thanks for your contribution served me very helpful
Hello friend quisioera know where you make your blog??? Is this page?
Can you help me
Hi
I do this blog in Buenos Aires, Argentina. Greetings.
I run this great wonderful thanks to your tutorial aora and I have an idea of how to use the timer.
grax x code
zi zirvio me!
○ ^ ^
thanks for this code I'm programming something bigger jejej
thanks ...
excellent code especially useful to develop some application to monitor waiting times of a process
Thanks a lot
anything!
and if to count down as serious?
A very good example I had cast in c + + programming with my profresor but had no idea it was in visual input basic.net thanks for a very simple and yet very atractivo.Gracias
only a very good thing, in the reset button if you press it is set to 0 but still running out of time for that alone you would have to put
Btn_reset_Click Private Sub (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_reset.Click
Timer1.Enabled = False
time = 0
minute = 0
second = 0
millisecond = 0
printTime ()
End Sub
Hi grace for the contribution
I want to know how to adapt to ASP with VB since by using the code page is doing postback
Thanks
many thanks, I was looking
VERY GOOD INFORMATION saved me from A TROUBLE
..
..
THANKS
Thank you very much for the contributions. They are very clear and very good.
Very good contribution, is what I was looking for!
thanks
Can you tell me as you did with the label1.refresh ()
Thank you.