Jump to content

Cronometro Regressivo


cra2sh
 Share

Recommended Posts

Boa noite pessoal,

Alguém me pode dar aqui uma ajudinha em C#, criei um cronometro regressivo mas estou ainda a tentar achar a melhor maneira de remover o "-" que aparecem, ex: -01:-59:-111, pretendia que aparecesse 01:59:111.

        DateTime now;
        TimeSpan diff;

        private void bt_start_Click(object sender, EventArgs e)
        {
            now = DateTime.Now.AddMinutes(2);
            timer.Enabled = true;
        }

        private void bt_stop_Click(object sender, EventArgs e)
        {
            timer.Enabled = false;
        }

        private void timer_Tick_1(object sender, EventArgs e)
        {
            diff = DateTime.Now.Subtract(now);
            this.lb_timer.Text = String.Format("{0:D2}:{1:D2}:{2:D3}", diff.Minutes, diff.seconds, diff.milliseconds);
        }
Link to comment
Share on other sites

Já consegui remover mas agora fica assim 1:59:111, ou seja, o formato agora não esta a funcionar devido ao ToString()

        private void timer_Tick_1(object sender, EventArgs e)
        {
            diff = DateTime.Now.Subtract(now);

            string minutes = diff.Minutes.ToString().Substring(1);
            string seconds = diff.Seconds.ToString().Substring(1);
            string milliseconds = diff.Milliseconds.ToString().Substring(1);

            this.lb_timer.Text = String.Format("{0:D2}:{1:D2}:{2:D3}", minutes, seconds, milliseconds);
            
        }
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.