c# 定时器 System.Windows.Forms.Timer
System.Windows.Forms.Timer例程:
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 WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
private void button1_Click(object sender, EventArgs e)
{
myTimer.Tick += new EventHandler(CallBack);
myTimer.Enabled = true;
myTimer.Interval = 1000;
}
private void CallBack(object sender, EventArgs e)
{
textBox1.Text = DateTime.Now.ToLongTimeString().ToString();
}
private void button2_Click(object sender, EventArgs e)
{
myTimer.Stop();
}
}
}
样例截图:


浙公网安备 33010602011771号