using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Counter{ public partial class Counter1 : Form { public int seconds; public int minutes; public int hours; public bool paused; public Counter1() { InitializeComponent(); } private void CntrStart_Click(object sender, EventArgs e) { if (paused != true) { if ((MinTxtBox.Text != "") && (SecTxtBox.Text != "")) { Timer1.Enabled = true; CntrPause.Enabled = true; CntrStart.Enabled = false; CntrStop.Enabled = true; try { minutes = System.Convert.ToInt32(MinTxtBox.Text); seconds = System.Convert.ToInt32(SecTxtBox.Text); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Please Enter Values in ALL Boxes!"); } } else { Timer1.Enabled = true; paused = false; CntrStart.Enabled = false; CntrPause.Enabled = true; } } private void Timer1_Tick(object sender, EventArgs e) { //Verifying that the time specified has not passed yet if ((minutes == 0) && (hours == 0) && (seconds == 0)) { /*this makes it so that if the time has passed it will clear all the fields and also shows the message notifying that time is done*/ PrdTimer.Enabled = false; MessageBox.Show(SecTxtBox.Text); CntrPause.Enabled = false; CntrStop.Enabled = false; CntrStart.Enabled = true; MinTxtBox.Clear(); SecTxtBox.Clear(); MinTxtBox.Enabled = true; SecTxtBox.Enabled = true; MinLbl.Text = "00"; SecLbl.Text = "00"; } else { if (seconds < 1) { seconds = 59; if (minutes == 0) { minutes = 59; if (hours != 0) hours -= 1; } else { minutes -= 1; } } else seconds -= 1; /*Displays the current values of hours,minutes, and seconds in the appropriate fields*/ MinLbl.Text = minutes.ToString(); SecLbl.Text = seconds.ToString(); } } private void CntrPause_Click(object sender, EventArgs e) { //This section control pausing the timer CntrTimer.Enabled = false; paused = true; CntrPause.Enabled = false; CntrStart.Enabled = true; } private void CntrStop_Click(object sender, EventArgs e) { //This section controls stopping the timer completley CntrTimer.Enabled = false; paused = false; CntrPause.Enabled = false; CntrStop.Enabled = false; CntrStart.Enabled = true; MinTxtBox.Clear(); SecTxtBox.Clear(); MinTxtBox.Enabled = true; SecTxtBox.Enabled = true; MinLbl.Text = "00"; SecLbl.Text = "00"; } } }