您的位置:首页 > 其它

winfrom弹出窗口用timer控件控制倒计时20秒后关闭

2007-04-05 10:12 465 查看
功能描述:

这个是我做自动注册软件的一部分功能.弹出子窗体,在子窗体上显示倒计时20秒(每一秒减一),如果用户在子窗体上的textbox中输入,则倒计时停止,否则到0的时候自动关闭子窗体.

代码如下:

private int count;

private void Form2_Load(object sender, System.EventArgs e)

{

//倒计时20秒
count = 0;
btm.Text = "";
this.timer1.Enabled=true;
this.timer1.Start();

}

private void timer1_Tick(object sender, System.EventArgs e)
{
Console.WriteLine(count);
count++;
this.d_time.Text="本窗体将在"+(20-count)+"秒以后关闭!";
if(this.btm.Text != "")
{
this.timer1.Stop();
}
else if(count==20)
{
this.timer1.Stop();
this.Close();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: