我在我的代码中使用计时器,假设当计时器停止在 0 时,消息框提示我您已超时并显示两个按钮“重试”和“取消”。指导我使用该功能,即当我按下消息框上的“取消”按钮时,它会退出整个窗体。下面是 timer_tick 事件的 if 条件:
int duration = 10;
private void timer1_Tick(object sender, EventArgs e)
{
//shows message that time is up!
duration--;
timer_label1.Text = duration.ToString();
if (duration == 0)
{
timer1.Stop();
MessageBox.Show("You Timed Out", "Oops", MessageBoxButtons.RetryCancel, MessageBoxIcon.Stop);
}
}
private void start_game_button19_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Start();
}