從工具拉一個 ,屬性:
Enbled:True 啟動
Interval:1000 1000=1秒,1秒觸動一次timer1_Tick事件
程式碼:
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;
using System.Diagnostics;
namespace 進階時鐘
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
y_txt.Text = DateTime.Now.Year.ToString();
m_txt.Text = DateTime.Now.Month.ToString();
d_txt.Text = DateTime.Now.Day.ToString();
h_txt.Text = DateTime.Now.Hour.ToString();
mi_txt.Text = DateTime.Now.Minute.ToString();
s_txt.Text = DateTime.Now.Second.ToString();
w_txt.Text = DateTime.Now.DayOfWeek.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
Process.Start("shutdown.exe","-a");
}
private void button3_Click(object sender, EventArgs e)
{
Process.Start("shutdown.exe","-s -t " + sec_txt.Text + " -f");
}
}
}