码迷,mamicode.com
首页 > Windows程序 > 详细

C# WinForm定时触发事件

时间:2015-01-19 20:30:55      阅读:539      评论:0      收藏:0      [点我收藏+]

标签:

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

 

C# WinForm定时触发事件

标签:

原文地址:http://www.cnblogs.com/mtsl/p/4234503.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!