JayBeeOH

Count Down Timer Demo

Jun 22nd, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.96 KB | None | 0 0
  1. '------------------------------------------------------------------------------------------
  2. '           Notice of My Copyright and Intellectual Property Rights
  3. '
  4. ' Any intellectual property contained within the program by Joseph L. Bolen remains the
  5. ' intellectual property of the Joseph L. Bolen. This means that no person may distribute,
  6. ' publish or provide such intellectual property to any other person or entity for any
  7. ' reason, commercial or otherwise, without the express written permission of Joseph L. Bolen.
  8. '
  9. '                 Copyright © 2016. All rights reserved.
  10. '        All trademarks remain the property of their respective owners.
  11. '-------------------------------------------------------------------------------------------
  12. ' Program Name:   Count Down Timer Demo
  13. '
  14. ' Author:         Joseph L. Bolen
  15. ' Date Created:   22 JUN 2016
  16. '
  17. ' Description:    This program demonstrates the Timer component and its Tick event.
  18. '                 Also, the program shows the use of the TimeSpan class.
  19. '
  20. '                 Documentation is at:
  21. '                   App's screen image is at: http://imgur.com/kEAb7h9
  22. '                   App's Visual Basic .NET code is at http://pastebin.com/g80jutPz
  23. '-------------------------------------------------------------------------------------------
  24.  
  25. Public Class CountDownForm
  26.  
  27.     Private secondsRemaining As Integer
  28.  
  29.     Private Sub CountDownForm_Load(sender As Object, e As EventArgs) _
  30.         Handles MyBase.Load
  31.  
  32.         MyTimer.Interval = 1000 ' 1000 milliseconds = 1 second
  33.     End Sub
  34.  
  35.     Private Sub MyTimer_Tick(sender As Object, e As EventArgs) _
  36.         Handles MyTimer.Tick
  37.  
  38.         If secondsRemaining > 0 Then
  39.             Dim ts As New TimeSpan(0, 0, secondsRemaining)
  40.             TimeRemainingLabel.Text = ts.ToString("hh\:mm\:ss")
  41.             secondsRemaining -= 1
  42.         Else
  43.             MyTimer.Stop()
  44.             Beep()
  45.             TimeRemainingLabel.ForeColor = Color.Red
  46.             TimeRemainingLabel.Text = "Times Up!"
  47.             'MessageBox.Show("Times Up!",
  48.             '                Me.Text,
  49.             '                MessageBoxButtons.OK,
  50.             '                MessageBoxIcon.Information)
  51.         End If
  52.     End Sub
  53.  
  54.     Private Sub StartButton_Click(sender As Object, e As EventArgs) _
  55.         Handles StartButton.Click
  56.  
  57.         secondsRemaining = Convert.ToInt32((HoursNumUpDwn.Value * 3600) + (MinutesNumUpDwn.Value * 60) + SecondsNumUpDwn.Value)
  58.         StartButton.Enabled = False
  59.         SetTimeGroupBox.Enabled = False
  60.         MyTimer.Start()
  61.     End Sub
  62.  
  63.     Private Sub ResetButton_Click(sender As Object, e As EventArgs) _
  64.         Handles ResetButton.Click
  65.  
  66.         ResetForm()
  67.     End Sub
  68.  
  69.     Private Sub ResetForm()
  70.  
  71.         MyTimer.Stop()
  72.         StartButton.Enabled = True
  73.         SetTimeGroupBox.Enabled = True
  74.         TimeRemainingLabel.ForeColor = Control.DefaultForeColor
  75.         TimeRemainingLabel.Text = String.Empty
  76.     End Sub
  77. End Class
Advertisement
Add Comment
Please, Sign In to add comment