Click here to Skip to main content
Click here to Skip to main content

Simple countdown chronometer

, 11 Jun 2008
Rate this:
Please Sign up or sign in to vote.
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.

 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).

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

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)

About the Author

pechan00000
Systems / Hardware Administrator
Mexico Mexico
No Biography provided

Comments and Discussions

 
GeneralThis Program is wrong! PinmemberCAC2012-Mar-10 5:43 
QuestionDateTime.ToString PinmemberPIEBALDconsult11-Jun-08 9:09 
AnswerRe: DateTime.ToString Pinmemberpechan0000011-Jun-08 11:59 
GeneralRe: DateTime.ToString PinmemberPIEBALDconsult11-Jun-08 17:23 
GeneralRe: DateTime.ToString Pinmemberpechan0000011-Jun-08 17:26 
GeneralA 1mb download and... PinmvpJohn Simmons / outlaw programmer11-Jun-08 8:41 
GeneralRe: A 1mb download and... Pinmembermahan11011011011-Jun-08 19:15 
GeneralRe: A 1mb download and... PinmvpJohn Simmons / outlaw programmer11-Jun-08 23:16 
GeneralRe: A 1mb download and... Pinmemberroyrodsson8-Sep-08 21:37 
GeneralRe: A 1mb download and... PinmvpJohn Simmons / outlaw programmer8-Sep-08 23:17 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 11 Jun 2008
Article Copyright 2008 by pechan00000
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid