using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { // 时钟定时器 System.Timers.Timer timer = new System.Timers.Timer(); // 实例化 public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString()); } private void button2_Click(object sender, EventArgs e) { timer.Interval = 1000; // 间隔时间 timer.Elapsed += new System.Timers.ElapsedEventHandler(button1_Click); // 到时间后执行 timer.AutoReset = true; // 是否一直执行 timer.Enabled = true; // 是否执行 timer.Start(); // 开始 } } }