实现效果:
知识运用:
Timer组件的interval属性 //获取或设置Timer组件Tick事件发生的时间间隔
public int Interval {get;set}
NumericUpDown控件的Value属性 //获取或设置数字显示框的值
public decimal Value {get;set;}
实现代码:
private void button1_Click(object sender, EventArgs e) { DateTime get_time1 = DateTime.Now; DateTime sta_ontime1=Convert.ToDateTime(label4.Text.Trim().ToString()); get_df = DateAndTime.DateDiff("s",get_time1,sta_ontime1,FirstDayOfWeek.Sunday,FirstWeekOfYear.FirstFourDays); if (get_df > 0) { if (timer2.Enabled != true) { timer2.Enabled = true; label6.Text = "闹钟已启动"; label7.Text = "剩余" + get_df.ToString() + "秒"; } else { MessageBox.Show("闹钟已启动 请取消后再试"); } } else { long hour = 24 * 3600 + get_df; timer2.Enabled = true; label6.Text = "闹钟已启动"; label7.Text = "剩余" + hour.ToString() + "秒"; } }