功能描述:
因为在程序退出时需要确认是否是误操作,所以加了密码输入的子窗体,子窗体在20秒内会自动关闭
代码如下:
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.label2.Text="本窗体将在"+(20-count)+"秒以后关闭!"; if(this.btm.Text != "") { this.timer1.Stop(); } else if(count==20) { this.timer1.Stop(); this.Close(); } }