How to make a Stopwatch
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
6 posts
Page 1 of 1
Hello everyone,
Today I'm going to show you how to create a stopwatch application. I just made one yesterday and it was a basic one, so I'm posting a tutorial. What this stopwatch does it is that you can start it, stop it, reset it, and mark the current time. Please don't post negative/disappointing comments.
---------------------------------------------------------------------------
First of all, open Visual Basic 2008, create a new project, choose Windows Forms Application, type in the textbox Stopwatch and press the OK button. As soon as you have done this, the Form1 will appear on the screen on which we will design our application and code it.
First we will do the designing and then the coding. So now we will change the Form1's properties to make it look good. Change the Form1's Text property to Stopwatch. Change it's StartPosition property to CenterScreen. Change it's FormBorderStyle to FixedSingle. Change it's MaximizeBox property to False. Change it's Size property to 537, 174.
Now add the following things to the form:
(1)_ 1 Label. Change it's AutoSize property to False and it's BorderStyle property to FixedSingle. Resize it to fit the top of the form. Change it's TextAllign property to MiddleCenter. Change it's Font property to "Microsoft Sans Serif, 39.75pt, style=Bold" and it's Text property to "00:00:00:000".
(2)_ 4 Buttons. Change Button1's Text property to Start, Button2's to Stop, Button3's to Reset and Button4's to Mark.
(3)_ 1 ListBox.
(4)_ 1 Timer. Change it's Interval property to 1.
Now is the time to code Form1 and it's components. So right-click on the form in the Solution Explorer and click View Code.
Type the following code before Public Class Form1:
Well, that's all. It was real easy, wasn't it?
---------------------------------------------------------------------------
Voila! You have just completed making a Stopwatch with some easy-to-use features. Now debug and run it by pressing the Start Debugging button located at the main toolstrip. Test it, if it works fine then its SAVING time. You can save your project by going to File -> Save All and then pressing Save.
And there! You have your project and application that works. If you have any problem or can't understand something, please feel free to ask by either a comment or by PM. I have also attached a screenshot.
Please use the Give Thanks button and the Reputation System to appreciate my hard work. I have wrote this tutorial while making a Stopwatch project myself so you can download the source file in the attachments.
Thank you.
![Image]()
Today I'm going to show you how to create a stopwatch application. I just made one yesterday and it was a basic one, so I'm posting a tutorial. What this stopwatch does it is that you can start it, stop it, reset it, and mark the current time. Please don't post negative/disappointing comments.
---------------------------------------------------------------------------
First of all, open Visual Basic 2008, create a new project, choose Windows Forms Application, type in the textbox Stopwatch and press the OK button. As soon as you have done this, the Form1 will appear on the screen on which we will design our application and code it.
First we will do the designing and then the coding. So now we will change the Form1's properties to make it look good. Change the Form1's Text property to Stopwatch. Change it's StartPosition property to CenterScreen. Change it's FormBorderStyle to FixedSingle. Change it's MaximizeBox property to False. Change it's Size property to 537, 174.
Now add the following things to the form:
(1)_ 1 Label. Change it's AutoSize property to False and it's BorderStyle property to FixedSingle. Resize it to fit the top of the form. Change it's TextAllign property to MiddleCenter. Change it's Font property to "Microsoft Sans Serif, 39.75pt, style=Bold" and it's Text property to "00:00:00:000".
(2)_ 4 Buttons. Change Button1's Text property to Start, Button2's to Stop, Button3's to Reset and Button4's to Mark.
(3)_ 1 ListBox.
(4)_ 1 Timer. Change it's Interval property to 1.
Now is the time to code Form1 and it's components. So right-click on the form in the Solution Explorer and click View Code.
Type the following code before Public Class Form1:
Code: Select all
Write the following code by double-clicking Timer1:
Dim StopWatch As New Diagnostics.Stopwatch
Code: Select all
This is the code for Button1 which we call Start:
Dim elapsed As TimeSpan = Me.StopWatch.Elapsed
Label1.Text = String.Format("{0:00}:{1:00}:{2:00}:{3:00}", Math.Floor(elapsed.TotalHours), elapsed.Minutes, elapsed.Seconds, elapsed.Milliseconds)
Code: Select all
This is the code for Button2 which we call Stop:
Timer1.Start()
Me.StopWatch.Start()
Code: Select all
This is the code for Button3 which we call Reset:
Timer1.Stop()
Me.StopWatch.Stop(
Code: Select all
This is the code for Button4 which we call Mark:
Me.StopWatch.Reset()
Label1.Text = "00:00:00:000"
ListBox1.Items.Clear()
Code: Select all
ListBox1.Items.Add(Label1.Text)
Well, that's all. It was real easy, wasn't it?
---------------------------------------------------------------------------
Voila! You have just completed making a Stopwatch with some easy-to-use features. Now debug and run it by pressing the Start Debugging button located at the main toolstrip. Test it, if it works fine then its SAVING time. You can save your project by going to File -> Save All and then pressing Save.
And there! You have your project and application that works. If you have any problem or can't understand something, please feel free to ask by either a comment or by PM. I have also attached a screenshot.
Please use the Give Thanks button and the Reputation System to appreciate my hard work. I have wrote this tutorial while making a Stopwatch project myself so you can download the source file in the attachments.
Thank you.

Great tutorial yours is better than mine 100%
+rep
+rep
Code'N'Stuff
OneTeam..OneDream
Join ABSplash Team & Earn $$
ABSplash Site - Workpad - (VB) Custom Buttons 2 ways
OneTeam..OneDream
Join ABSplash Team & Earn $$
ABSplash Site - Workpad - (VB) Custom Buttons 2 ways
Good tutorial, simple yet effective!
Practice makes perfect!
VIP since: 6-10-2011
VIP since: 6-10-2011
6 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023