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();
        }
    }
}

样例截图:

posted @ 2019-11-13 23:37  黑色的夢  阅读(1282)  评论(0)    收藏  举报