在 form1 的顶部,我有:
private int seconds;
private int minutes;
private int hours;
在构造函数中:
seconds = 0;
minutes = 20;
hours = 0;
label9.Visible = false;
label9.Text = "00:00:00";
然后是计时器 3 滴答事件。我在 timer3 滴答事件上使用了一个断点,我看到分钟和秒正在倒数,但标签 9 没有更新。
也许 label9 上的 string.Format 不正确?
private void timer3_Tick(object sender, EventArgs e)
{
// Verify if the time didn't pass.
if ((minutes == 0) && (hours == 0) && (seconds == 0))
{
// If the time is over, clear all settings and fields.
// Also, show the message, notifying that the time is over.
timer3.Enabled = false;
label9.Visible = true;
label9.Text = "00:00:00";
}
else
{
// Else continue counting.
if (seconds < 1)
{
seconds = 59;
if (minutes == 0)
{
minutes = 59;
if (hours != 0)
hours -= 1;
}
else
{
minutes -= 1;
}
}
else
seconds -= 1;
// Display the current values of hours, minutes and seconds in
// the corresponding fields.
label7.Visible = true;
label9.Visible = true;
label9.Text = string.Format("{00} : {00} : {00}", hours.ToString(), minutes.ToString(),seconds.ToString());
}
}
我最后在标签 9 上看到的只是:0:0:0 就是这样,我没有看到倒数 20 分钟。