积极答复者
MessageBox.Show()的问题

问题
-
private void timer2_Tick(object sender,EventArgs e)
{
if(isecond<0)
{
timer2.Stop();
MessageBox.Show("小于系统时间","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else if(isecond==0)
{
timer2.Stop();
MessageBox.Show("时间到");
}
else
labtime.Text="剩余"+(--isecond)+"秒";
}=====================================
上段代码中,红色代码与蓝色代码(timer2.Stop()与MessageBox.Show())互换一下位置,就会出现一个问题,程序执行MessageBox.Show()后就会路过timer2.Stop();,如果没有点击MessageBox.Show()弹出的窗口,就会一直不停的弹出窗口。如何才能在用户响应MessageBox.Show()对话框之后,程序才继续执行。
答案
全部回复
-
MessageBox.Show()是阻塞方法,当弹出的窗口没有被点掉之前,timer2.Stop()是执行不到的,但是Timer一直在tick,所以会一直弹出窗口。
Shuhai Shen - http://leonax.net