' Program counts down from one hour for purposes of monitoring lab time ' Programmer: George Robinson ' Begin: 28 January 2020 ' Final: 5 February 2020 Option Strict On Option Explicit On Public Class frmCountdown Const X As Integer = 60 Const Y As Integer = 120 Const Z As Integer = 180 Dim dtmCountdown As DateTime = DateTime.Now.AddMinutes(X) Private Sub frmCountdown_Load(sender As Object, e As EventArgs) Handles Me.Load lblProgrammer.Text = "Programmer: George Robinson" tmrCountdown.Interval = 1000 tmrCountdown.Enabled = True lblDate.Text = Now.ToString End Sub Private Sub tmrCountdown_Tick(sender As Object, e As EventArgs) Handles tmrCountdown.Tick lblDate.Text = Now.ToString ' Establishes remaining time for start of timer Dim remaining As TimeSpan = dtmCountdown.Subtract(Now) remaining = New TimeSpan(remaining.Hours, remaining.Minutes, remaining.Seconds) ' Colors the Text Label for timer to dark red. If remaining.TotalSeconds < 300 Then lblCountdown.ForeColor = Color.DarkRed End If ' If Time reaches Zero, expands window to maximized and sets as TopMost window. If remaining.TotalSeconds <= 0 Then remaining = TimeSpan.Zero Me.WindowState = FormWindowState.Maximized Me.TopMost = True Else ' Updates the time on the label. remaining = New TimeSpan(remaining.Hours, remaining.Minutes, remaining.Seconds) lblCountdown.Text = remaining.ToString End If End Sub Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click ' End the Top Most, Maximized Window State for the timer to indicate the time is done. Me.WindowState = FormWindowState.Normal Me.TopMost = False lblCountdown.ForeColor = Color.Black ' Resets time to 1 hour and restarts the clock dtmCountdown = DateTime.Now.AddMinutes(X) tmrCountdown.Enabled = True End Sub Private Sub btn2Hour_Click(sender As Object, e As EventArgs) Handles btn2Hour.Click ' End the Top Most, Maximized Window State for the timer to indicate the time is done. Me.WindowState = FormWindowState.Normal Me.TopMost = False lblCountdown.ForeColor = Color.Black ' Resets time to 2 hour and restarts the clock dtmCountdown = DateTime.Now.AddMinutes(Y) tmrCountdown.Enabled = True End Sub Private Sub btn3Hour_Click(sender As Object, e As EventArgs) Handles btn3Hour.Click ' End the Top Most, Maximized Window State for the timer to indicate the time is done. Me.WindowState = FormWindowState.Normal Me.TopMost = False lblCountdown.ForeColor = Color.Black ' Resets time to 3 hour and restarts the clock dtmCountdown = DateTime.Now.AddMinutes(Z) tmrCountdown.Enabled = True End Sub Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click ' End the Top Most, Maximized Window State for the timer to indicate the time is done. Me.WindowState = FormWindowState.Normal Me.TopMost = False lblCountdown.ForeColor = Color.Black 'Stops the timer and sets to 00:00:00 tmrCountdown.Enabled = False Dim dtmCountdown As DateTime = DateTime.Now Dim remaining As TimeSpan = dtmCountdown.Subtract(Now) remaining = New TimeSpan(remaining.Hours, remaining.Minutes, remaining.Seconds) lblCountdown.Text = remaining.ToString End Sub Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click 'Closes program Me.Close() End Sub End Class