Count down Timer for Windows App

edited October 2015 in C and C++

I looked up a youtube video on how to make a count down timer but it was a going up timer. I tried altering it but no success.

#pragma endregion
    public:
        int seconds;
        int hours;
        int minutes;
    public: void start()
    {
        seconds--;
        if (seconds < 00)
        {
            lblseconds->Text = Convert::ToString("0" - seconds);
        }else
        {
            lblseconds->Text = Convert::ToString(seconds);
        }
        if (seconds == 00)
        {

            minutes--;
            seconds = 60;
            if (minutes < 00)
            {
                lblminutes->Text = Convert::ToString("0" - minutes);
            }
            else
            {
                lblminutes->Text = Convert::ToString(minutes);
            }
            if (minutes == 00)
            {
                hours--;
                minutes = 60;
                seconds = 60;
                if (hours < 10)
                {
                    lblhours->Text = Convert::ToString("0" - hours);
                }
                else
                {
                    lblhours->Text = Convert::ToString(hours);
                }
            }
        }

    }
private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) 
{

}
private: System::Void bntstart_Click(System::Object^  sender, System::EventArgs^  e) 
{
    tm1->Enabled = true;
}
private: System::Void btnstop_Click(System::Object^  sender, System::EventArgs^  e) 
{
    tm1->Enabled = false;
}
private: System::Void tm1_Tick(System::Object^  sender, System::EventArgs^  e)
{
     start();
}
private: System::Void btnreset_Click(System::Object^  sender, System::EventArgs^  e) 
{
    lblseconds->Text = "15";
    lblminutes->Text = "00";
    lblhours->Text = "06";
    hours = 06;
    seconds = 15;
    minutes = 00;
}
};
}

And the original Code is this, for counting up

#pragma endregion
    public:
        int seconds;
        int hours;
        int minutes;
    public: void start()
    {
        seconds++;
        if (seconds < 10)
        {
            lblseconds->Text = Convert::ToString("0" + seconds);
        }else
        {
            lblseconds->Text = Convert::ToString(seconds);
        }
        if (seconds == 60)
        {

            minutes++;
            seconds = 00;
            if (minutes < 10)
            {
                lblminutes->Text = Convert::ToString("0" + minutes);
            }
            else
            {
                lblminutes->Text = Convert::ToString(minutes);
            }
            if (minutes == 60)
            {
                hours++;
                minutes = 00;
                seconds = 00;
                if (hours < 10)
                {
                    lblhours->Text = Convert::ToString("0" + hours);
                }
                else
                {
                    lblhours->Text = Convert::ToString(hours);
                }
            }
        }

    }
private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) 
{

}
private: System::Void bntstart_Click(System::Object^  sender, System::EventArgs^  e) 
{
    tm1->Enabled = true;
}
private: System::Void btnstop_Click(System::Object^  sender, System::EventArgs^  e) 
{
    tm1->Enabled = false;
}
private: System::Void tm1_Tick(System::Object^  sender, System::EventArgs^  e)
{
     start();
}
private: System::Void btnreset_Click(System::Object^  sender, System::EventArgs^  e) 
{
    lblseconds->Text = "15";
    lblminutes->Text = "00";
    lblhours->Text = "06";
    hours = 06;
    seconds = 58;
    minutes = 59;
}
};
}

My goal for this code is to make it count down from any time i want to set it at and when it all reaches 00:00:00 i want it to make a sound for a notifier.
http://imgur.com/PdliNy2

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories