首页 > 代码库 > WinForm中Timer倒计时
WinForm中Timer倒计时
添加一个Timer控件:
在初始化代码中
public Form1() { InitializeComponent(); button_Read.Enabled = false; button_Start.Enabled = false; timer1.Enabled = true; timer1.Interval = 1000; timer1.Start(); }
双击Timer控件,在其事件中
private void timer1_Tick(object sender, EventArgs e) { string time = button_Read.Text; string[] arr = time.Split(‘:‘); if (arr.Length == 2) { int min, second; if (int.TryParse(arr[0], out min) && int.TryParse(arr[1], out second)) { second--; if (second < 0) { second = 59; min--; } button_Read.Text = min + ":" + second; button_Start.Text = min + ":" + second; if (min ==0 && second ==0 ) { button_Read.Text = "读取ini.txt"; button_Start.Text = "开始测试"; button_Read.Enabled = true; button_Start.Enabled = true; } } } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。