user2760148
user2760148

Reputation: 427

How do i make that the counter in the timer tick event will count 5 minutes back?

The code is :

private void timer1_Tick(object sender, EventArgs e)
        {
            count += 1;
            countBack --;
            TimerCount.Text = TimeSpan.FromSeconds(countBack).ToString();
            TimerCount.Visible = true;
            if (count == 300)
            {
                timer1.Enabled = false;
                count = 0;
            }
        }

I used before the variable count to count to 5 minutes. But i want only to use the countBack variable to count back from 5 minutes to 0 and also show it in the TimerCount.

countBack is int and in the constructor i just set it to 5. countBack = 5;

How can i make that i will use only the countBack and when it get to 0 stop the timer reset the countBack to 5 and show the countBack in the TimerCount ?

Upvotes: 0

Views: 157

Answers (1)

King King
King King

Reputation: 63317

    private void timer1_Tick(object sender, EventArgs e)
    {
        count ++;
        countBack = 5 - count/60;
        TimerCount.Text = TimeSpan.FromSeconds(count).ToString();
        if(!TimerCount.Visible) TimerCount.Visible = true;
        if (count == 300){
            timer1.Enabled = false;
            count = 0;
        }
    }

NOTE: the code above is just a simple modification to your code, we can do it better with more specific context.

Upvotes: 2

Related Questions