1.先拖拉出一個Timer元件
2.接著就是將Timer的Enabled屬性設成True
3.設定Interval(1000就是一秒)
4.點選Timer元件在裡面寫code
ex:
private void timer1_Tick_1(object sender, EventArgs e)
{
//將系統時間時-分-秒指定給觸發變數triggerTime
triggerTime = DateTime.Now.Hour.ToString().PadLeft(2, '0') + DateTime.Now.Minute.ToString().PadLeft(2, '0') + DateTime.Now.Second.ToString().PadLeft(2, '0');
if (triggerTime.ToString() == txtTrigger.Text.PadRight(6,'0'))
{
//如果觸發時間到就執行
btnSearch.Text = triggerTime.Substring(0, 2).ToString() + " : " + triggerTime.Substring(2, 2).ToString() + " : " + triggerTime.Substring(4, 2).ToString();
MessageBox.Show("完成時間:" + DateTime.Now.ToString());
timer1.Stop();
timer1.Start();
}
}