星期一, 2月 02, 2015

筆記-C# Timer使用筆記

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DB_Backup
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            //設定觸發時間
            timer1.Interval = 1000;
            //啟動Timer
            timer1.Enabled = true;
        
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //取的當前時間
            DateTime DT_now = DateTime.Now;
            //設定tbTime textBox text顯示當前日期時間
            tbTime.Text = DT_now.Year + "/" + DT_now.Month + "/" + DT_now.Day + "  " + DT_now.Hour + ":" + DT_now.Minute + ":" + DT_now.Second;


           
        }
    }
}

沒有留言: