Description
A count-down timer I made to keep track of time, primarily for extreme programming sprints/tasks. Source in two parts, first Designer and then code.
Source Code
/*
* frmMain.Designer.vb
*/
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> Partial Class frmMain
#Region "Windows Form Designer generated code "
<System.Diagnostics.DebuggerNonUserCode()> Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
End Sub
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
If Disposing Then
If Not components Is Nothing Then
components.Dispose()
End If
End If
MyBase.Dispose(Disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
Public ToolTip1 As System.Windows.Forms.ToolTip
Public WithEvents txtTime As System.Windows.Forms.TextBox
Public WithEvents txtInfo As System.Windows.Forms.TextBox
Public WithEvents tmrTime As System.Windows.Forms.Timer
Public WithEvents cmdStop As System.Windows.Forms.Button
Public WithEvents cmdStart As System.Windows.Forms.Button
Public WithEvents lblTime As System.Windows.Forms.Label
Public WithEvents lblInfo As System.Windows.Forms.Label
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmMain))
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.txtTime = New System.Windows.Forms.TextBox
Me.txtInfo = New System.Windows.Forms.TextBox
Me.tmrTime = New System.Windows.Forms.Timer(Me.components)
Me.cmdStop = New System.Windows.Forms.Button
Me.cmdStart = New System.Windows.Forms.Button
Me.lblTime = New System.Windows.Forms.Label
Me.lblInfo = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'txtTime
'
Me.txtTime.AcceptsReturn = True
Me.txtTime.BackColor = System.Drawing.SystemColors.Window
Me.txtTime.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.txtTime.Cursor = System.Windows.Forms.Cursors.IBeam
Me.txtTime.Font = New System.Drawing.Font("Arial", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtTime.ForeColor = System.Drawing.SystemColors.WindowText
Me.txtTime.Location = New System.Drawing.Point(32, 24)
Me.txtTime.MaxLength = 0
Me.txtTime.Name = "txtTime"
Me.txtTime.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.txtTime.Size = New System.Drawing.Size(126, 37)
Me.txtTime.TabIndex = 5
Me.txtTime.Visible = False
'
'txtInfo
'
Me.txtInfo.AcceptsReturn = True
Me.txtInfo.BackColor = System.Drawing.SystemColors.Window
Me.txtInfo.BorderStyle = System.Windows.Forms.BorderStyle.None
Me.txtInfo.Cursor = System.Windows.Forms.Cursors.IBeam
Me.txtInfo.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtInfo.ForeColor = System.Drawing.SystemColors.WindowText
Me.txtInfo.Location = New System.Drawing.Point(8, 8)
Me.txtInfo.MaxLength = 0
Me.txtInfo.Name = "txtInfo"
Me.txtInfo.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.txtInfo.Size = New System.Drawing.Size(174, 13)
Me.txtInfo.TabIndex = 4
Me.txtInfo.Visible = False
'
'tmrTime
'
Me.tmrTime.Interval = 1000
'
'cmdStop
'
Me.cmdStop.BackColor = System.Drawing.SystemColors.Control
Me.cmdStop.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdStop.Enabled = False
Me.cmdStop.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdStop.ForeColor = System.Drawing.SystemColors.ControlText
Me.cmdStop.Location = New System.Drawing.Point(8, 64)
Me.cmdStop.Name = "cmdStop"
Me.cmdStop.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdStop.Size = New System.Drawing.Size(73, 33)
Me.cmdStop.TabIndex = 3
Me.cmdStop.Text = "Stop"
Me.cmdStop.UseVisualStyleBackColor = False
'
'cmdStart
'
Me.cmdStart.BackColor = System.Drawing.SystemColors.Control
Me.cmdStart.Cursor = System.Windows.Forms.Cursors.Default
Me.cmdStart.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.cmdStart.ForeColor = System.Drawing.SystemColors.ControlText
Me.cmdStart.Location = New System.Drawing.Point(104, 64)
Me.cmdStart.Name = "cmdStart"
Me.cmdStart.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.cmdStart.Size = New System.Drawing.Size(73, 33)
Me.cmdStart.TabIndex = 2
Me.cmdStart.Text = "Start"
Me.cmdStart.UseVisualStyleBackColor = False
'
'lblTime
'
Me.lblTime.AutoSize = True
Me.lblTime.BackColor = System.Drawing.SystemColors.Control
Me.lblTime.Cursor = System.Windows.Forms.Cursors.Default
Me.lblTime.Font = New System.Drawing.Font("Arial", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblTime.ForeColor = System.Drawing.SystemColors.ControlText
Me.lblTime.Location = New System.Drawing.Point(32, 24)
Me.lblTime.Name = "lblTime"
Me.lblTime.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.lblTime.Size = New System.Drawing.Size(141, 36)
Me.lblTime.TabIndex = 1
Me.lblTime.Text = "00:00:00"
'
'lblInfo
'
Me.lblInfo.AutoSize = True
Me.lblInfo.BackColor = System.Drawing.SystemColors.Control
Me.lblInfo.Cursor = System.Windows.Forms.Cursors.Default
Me.lblInfo.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblInfo.ForeColor = System.Drawing.SystemColors.ControlText
Me.lblInfo.Location = New System.Drawing.Point(8, 8)
Me.lblInfo.Name = "lblInfo"
Me.lblInfo.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.lblInfo.Size = New System.Drawing.Size(153, 14)
Me.lblInfo.TabIndex = 0
Me.lblInfo.Text = "Amount of time you've got left:"
'
'frmMain
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 14.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.BackColor = System.Drawing.SystemColors.Control
Me.ClientSize = New System.Drawing.Size(187, 103)
Me.Controls.Add(Me.txtTime)
Me.Controls.Add(Me.txtInfo)
Me.Controls.Add(Me.cmdStop)
Me.Controls.Add(Me.cmdStart)
Me.Controls.Add(Me.lblTime)
Me.Controls.Add(Me.lblInfo)
Me.Cursor = System.Windows.Forms.Cursors.Default
Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Location = New System.Drawing.Point(3, 22)
Me.MaximizeBox = False
Me.Name = "frmMain"
Me.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Text = "Mr. Countdown"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
#End Region
End Class
/*
* frmMain.vb
*/
Option Strict Off
Option Explicit On
Friend Class frmMain
Inherits System.Windows.Forms.Form
' Written by Me, because I'm great
Dim intMinutes, intSeconds, intHours As Short
Private Sub cmdStart_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdStart.Click
cmdStart.Enabled = False
cmdStop.Enabled = True
tmrTime.Enabled = True
End Sub
Private Sub cmdStop_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdStop.Click
cmdStart.Enabled = True
cmdStop.Enabled = False
tmrTime.Enabled = False
End Sub
Private Sub lblInfo_DoubleClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lblInfo.DoubleClick
txtInfo.Text = lblInfo.Text
txtInfo.Visible = True
End Sub
Private Sub lblTime_DoubleClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles lblTime.DoubleClick
If tmrTime.Enabled = True Then
Call MsgBox("You must stop the timer to change the time.", MsgBoxStyle.Information, "Mr. Timer")
Else
txtTime.Text = lblTime.Text
txtTime.Visible = True
End If
End Sub
Private Sub txtInfo_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtInfo.KeyPress
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
If KeyAscii = 13 Then
' If someone puts nothing, since the label auto-sizes
' then they could accidently make it to where nothing
' can be clicked on to fix it later. So we set it to
' something so at least they can click it.
If txtInfo.Text = "" Then
txtInfo.Text = "(None)"
End If
lblInfo.Text = txtInfo.Text
txtInfo.Visible = False
End If
eventArgs.KeyChar = Chr(KeyAscii)
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub
Private Sub txtTime_KeyPress(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.KeyPressEventArgs) Handles txtTime.KeyPress
Dim KeyAscii As Short = Asc(eventArgs.KeyChar)
On Error Resume Next
Dim strMinutes, strHours, strSeconds As String
Dim intTemp As Short
If KeyAscii = 13 Then
If txtTime.Text = "" Then
txtTime.Text = lblTime.Text
End If
''
'' Check syntax
''
If Mid(txtTime.Text, 3, 1) <> ":" Or Mid(txtTime.Text, 6, 1) <> ":" Then
Call MsgBox("Incorrect format, it must be ""hh:mm:ss""!", MsgBoxStyle.Information, "Mr. Timer")
GoTo EventExitSub
End If
strHours = Mid(txtTime.Text, 1, 2)
intTemp = Int(CDbl(strHours))
If intTemp < 0 Then
Call MsgBox("Incorrect format, it must be ""hh:mm:ss""!" & vbCrLf & vbCrLf & "Your hours are incorrect.", MsgBoxStyle.Information, "Mr. Timer")
GoTo EventExitSub
End If
strMinutes = Mid(txtTime.Text, 4, 2)
intTemp = Int(CDbl(strMinutes))
If intTemp < 0 Or intTemp > 59 Then
Call MsgBox("Incorrect format, it must be ""hh:mm:ss""!" & vbCrLf & vbCrLf & "Your minutes are incorrect.", MsgBoxStyle.Information, "Mr. Timer")
GoTo EventExitSub
End If
strSeconds = Mid(txtTime.Text, 7, 2)
intTemp = Int(CDbl(strSeconds))
If intTemp < 0 Or intTemp > 59 Then
Call MsgBox("Incorrect format, it must be ""hh:mm:ss""!" & vbCrLf & vbCrLf & "Your seconds are incorrect.", MsgBoxStyle.Information, "Mr. Timer")
GoTo EventExitSub
End If
intHours = Int(CDbl(strHours))
intMinutes = Int(CDbl(strMinutes))
intSeconds = Int(CDbl(strSeconds))
lblTime.Text = txtTime.Text
txtTime.Visible = False
End If
EventExitSub:
eventArgs.KeyChar = Chr(KeyAscii)
If KeyAscii = 0 Then
eventArgs.Handled = True
End If
End Sub
Private Sub tmrTime_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles tmrTime.Tick
Dim strMinutes, strHours, strSeconds As String
If intHours = 0 And intMinutes = 0 And intSeconds = 0 Then
cmdStart.Enabled = True
cmdStop.Enabled = False
tmrTime.Enabled = False
Exit Sub
End If
If intMinutes = 0 And intSeconds = 0 Then
intMinutes = 59
intSeconds = 59
intHours = intHours - 1
End If
If intSeconds = 0 Then
intSeconds = 59
intMinutes = intMinutes - 1
Else
intSeconds = intSeconds - 1
End If
strHours = Trim(Str(intHours))
If intHours < 10 Then
strHours = "0" & strHours
End If
strMinutes = Trim(Str(intMinutes))
If intMinutes < 10 Then
strMinutes = "0" & strMinutes
End If
strSeconds = Trim(Str(intSeconds))
If intSeconds < 10 Then
strSeconds = "0" & strSeconds
End If
lblTime.Text = strHours & ":" & strMinutes & ":" & strSeconds
End Sub
End Class