Click here to Skip to main content
15,886,026 members
Articles / Desktop Programming / Windows Forms
Article

Simple countdown chronometer

Rate me:
Please Sign up or sign in to vote.
2.20/5 (8 votes)
11 Jun 2008CPOL 68K   2.9K   23   10
Countdown chronometer i've used to help me when im in a exposition

Introduction

Someone ask me to develop a countdown chronometer to use it as a timing reference for expositions. So i did a simple code.

cronoNFun.jpg

Count Down Chronometer with progress bar

cronoFun.jpg

Using the code

This application has three parts: timer1_Tick, button1_click (Start Button), button2_click (restart button).

timer1_Tick:

label1 has the time of textBox1 converted in date time and extracted hours, minutes and seconds. Activates progress bar increment in progress bar step. When the time has gone plays a sound and pop up a message box to alert us.

C#
 label1.Text = Convert.ToString(hr) + ":" + Convert.ToString(min) +
":" + Convert.ToString(seg);
progressBar1.Increment(progressBar1.Step);
if (seg == 0 && min > 0)
{
 min--;
 seg = 59;
}
else if (seg == 0 && min == 0 && hr > 0)
{
 seg = 59; min = 59;
 hr--;
}
if (min == 0 && hr > 0)
{
 min = 59;
 hr--;
}
if (hr == 0 && min == 0 && seg == 0)
{
 timer1.Stop();
 SystemSounds.Beep.Play();
 MessageBox.Show("Listo! Se acab¢ el Tiempo", "ya!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
seg--;

Start button:

This button starts the chronometer setting the time parameters for the timer1 and the progress bar(sets the maximum progressBar property in seconds).

C#
private void button1_Click(object sender, EventArgs e)
{
 try
 {
    timer = Convert.ToDateTime(textBox1.Text);
    hr = timer.Hour;
    min = timer.Minute;
    seg = timer.Second;
    mil = timer.Millisecond;
    timer1.Start();
    textBox1.Enabled = false;
    button1.Enabled = false;
    progressBar1.Step = 1;
    progressBar1.Maximum = (min * 60) + seg + (hr * 60 * 60);
    progressBar1.Minimum = 0;
 }
 catch (Exception ex)
 {
  MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
 }
}

Reset button:

Stops timer1 and set label1.text in zero

C#
private void button2_Click(object sender, EventArgs e)
{ 
 label1.Text = "0:00:00";
 button1.Enabled = true;
 textBox1.Enabled = true;
 timer1.Stop();
}

Like you can see its so simple. Hope to be useful

Keep a running update of any changes or improvements you've made here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Systems / Hardware Administrator
Mexico Mexico
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralThis Program is wrong! Pin
CAC2012-Mar-10 5:43
CAC2012-Mar-10 5:43 
QuestionDateTime.ToString Pin
PIEBALDconsult11-Jun-08 9:09
mvePIEBALDconsult11-Jun-08 9:09 
AnswerRe: DateTime.ToString Pin
pechan0000011-Jun-08 11:59
pechan0000011-Jun-08 11:59 
GeneralRe: DateTime.ToString Pin
PIEBALDconsult11-Jun-08 17:23
mvePIEBALDconsult11-Jun-08 17:23 
GeneralRe: DateTime.ToString Pin
pechan0000011-Jun-08 17:26
pechan0000011-Jun-08 17:26 
GeneralA 1mb download and... Pin
#realJSOP11-Jun-08 8:41
mve#realJSOP11-Jun-08 8:41 
GeneralRe: A 1mb download and... Pin
mahan11011011011-Jun-08 19:15
mahan11011011011-Jun-08 19:15 
GeneralRe: A 1mb download and... Pin
#realJSOP11-Jun-08 23:16
mve#realJSOP11-Jun-08 23:16 
GeneralRe: A 1mb download and... Pin
royrodsson8-Sep-08 21:37
royrodsson8-Sep-08 21:37 
GeneralRe: A 1mb download and... Pin
#realJSOP8-Sep-08 23:17
mve#realJSOP8-Sep-08 23:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.