Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

[VB2008] Stopwatch Tutorial

timer

  • Please log in to reply
2 replies to this topic

#1 CuzImAwesome

CuzImAwesome

    CC Newcomer

  • Member
  • PipPip
  • 22 posts

Posted 20 October 2010 - 06:53 PM

Hey Guys! Im new here, so I thought i would post a tutorial. So here ya go!

-----------------------------------------------------------------------------------------------------------
Add a label to the form and change it's text to 00:00:00:000

To do that right click on the label and click on properties.

Change the font's size of the label. In the properties window, go to Font. The font dialog will show up. Under the size, choose the number 28 then click Ok.

Add a timer to the form. Right click on Timer1 and click on properties. In the properties window, change the interval property to 1.

Drag a listbox from the toolbox into the form.

Add a 3 buttons to the form and change it's text to Mark, Start, and Reset.

--------- CODES -------------------------------------------------------------------------------------------------
Form:
Public Class Form1

Private stopwatch As New Stopwatch

End Class

Timer:
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)


Start:
Timer1.Start()

Me.stopwatch.Start()

Button4.Enabled = False

Stop:
Timer1.Stop()

Me.stopwatch.Stop()

Button4.Enabled = True

Reset:
Me.stopwatch.Reset()

Label1.Text = "00:00:00:00"

ListBox1.Items.Clear()

Mark
ListBox1.Items.Add(ListBox1.Items.Count + 1 & " " & Label1.Text)

Hope This Helped!!!

Edited by CuzImAwesome, 21 October 2010 - 06:57 AM.

  • 0

#2 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 20 October 2010 - 07:02 PM

Nice tutorial, but I think you meant "Mark" to mark the time, not reset.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#3 GDesign

GDesign

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 24 April 2012 - 05:34 PM

thank you very much :)
  • 0





Also tagged with one or more of these keywords: timer

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download