I am doing a project using Visual Studio 2013 using C #. I want the timer to count from 120 minutes to 0 minutes, and when it reaches 0, a message box will show that the time is increasing. I also want the timer to reset when the reset button is pressed. However, when I pressed the reset button, even if the timer was reset, I pressed the start button, and the βTime upβ message box will appear, and the timer will not start. Please help me. I am a complete newbie in C #, so please try not to give me complex answers that are hard to understand. In addition, you will see me much more, because I will have additional questions. Thank you !! (These are my codes.)
private void startbutton_Click(object sender, EventArgs e) { timer.Enabled = true; foreach (var button in Controls.OfType<Button>()) { button.Click += button_Click; timer.Start(); button.BackColor = Color.DeepSkyBlue; } } private void stopandresetbutton_Click(object sender, EventArgs e) { button.BackColor = default(Color); timer.Stop(); timeleft = 0; timerlabel.Hide(); } int timeleft = 120; private void timer_Tick(object sender, EventArgs e) { if (timeleft > -1) { timerlabel.Text = timeleft + " minutes"; timeleft = timeleft - 1; } else { timer.Stop(); MessageBox.Show("Time up!"); } }
source share