Jump to content

[VB2008] Stopwatch Tutorial

- - - - -

  • Please log in to reply
2 replies to this topic

#1
CuzImAwesome

CuzImAwesome

    Newbie

  • Members
  • PipPip
  • 25 posts
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.


#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
Nice tutorial, but I think you meant "Mark" to mark the time, not reset.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
GDesign

GDesign

    Newbie

  • Members
  • Pip
  • 5 posts
thank you very much :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users