首先一個程序第一要素是logoide
在設置裏面能夠設置程序圖標,在ICON裏設置。this
ICON圖標能夠在網上下載。spa
這些都是表面功夫設計
程序中涉及到Buton、Label、Timer、Notiflcon控件3d
Button按鈕控件,能夠設計點擊事件orm
以下所示:blog
private void button1_Click(object sender, EventArgs e) { // int shi, fen, miao; if (Flag_True == 0) { Flag_True = 1; } else { button1.Text = "肯定"; label6.Text = " "; label7.Text = " "; label5.Text = " "; //label1.Text = "定時關機設置"; Flag_True = 0; } shi = (int)numericUpDown3.Value; fen = (int)numericUpDown2.Value; miao = (int)numericUpDown1.Value; time_set = shi * 3600 + fen * 60 + miao; }
label控件操做簡單事件
可以顯示字符,而且其成員有text,能夠隨時更改文本it
timer控件至關於嵌入式中的定時器,在屬性中行爲一欄中設置ENABLE 而且設置interval時間間隔500就是半秒。class
private void timer1_Tick(object sender, EventArgs e) { Int32 time_now; Int32 extra; if (Flag_True == 1) { if (DateTime.Now.Minute == fen && DateTime.Now.Hour == shi && DateTime.Now.Second == miao) { button1.Text = "取消"; label6.Text = "剩餘關機時間"; label7.Text = "秒"; label5.Text = "0"; System.Diagnostics.Process.Start("shutdown","-s -t 0");//關機程序 }//shutdown else { time_now = DateTime.Now.Second + DateTime.Now.Minute * 60 + DateTime.Now.Hour * 3600; extra = time_set - time_now; if (extra > 0) { button1.Text = "取消"; label6.Text = "剩餘關機時間"; label7.Text = "秒"; //extra/3600 label5.Text = extra.ToString(); } else { Flag_True = 0; } } } }
上面我每隔半秒進入中斷一次,判斷,若是已經設置過定時關機,就判斷是否到達關機時間,並顯示還剩多少秒關機。若是沒有設置定時關機,就不顯示。
其中button1和Label的text均可以隨時更改。
基本功能設置完成
接下來還有一個最小化到托盤的設置
用到Notiflcon控件
此控件設置最小化圖標,在設置裏能夠設置icon圖標。
他帶有的事件有鼠標單擊,鼠標雙擊,單擊,雙擊。
private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) { this.Visible = true; this.WindowState = FormWindowState.Normal; this.notifyIcon1.Visible = false; }
上述我設置了鼠標單擊,代碼裏是恢復可視化,正常窗口。
再之得設置程序最小化時隱藏在下邊
private void Form1_SizeChanged(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Hide(); this.notifyIcon1.Visible = true; } }
上述就是一個關機程序,本身作着玩的。。
總體構架以下圖所示。
namespace 關機任務管理V1._0 { public partial class Form1 : Form { int shi, fen, miao; Int32 time_set; int Flag_True = 0; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void numericUpDown1_ValueChanged(object sender, EventArgs e) { if (numericUpDown1.Value == -1) numericUpDown1.Value = 60; else if (numericUpDown1.Value == 61) numericUpDown1.Value = 0; } private void numericUpDown2_ValueChanged(object sender, EventArgs e) { if (numericUpDown2.Value == -1) numericUpDown2.Value = 60; else if (numericUpDown2.Value == 61) numericUpDown2.Value = 0; } private void numericUpDown3_ValueChanged(object sender, EventArgs e) { if (numericUpDown3.Value == 25) numericUpDown3.Value = 0; else if (numericUpDown3.Value == -1) numericUpDown3.Value = 24; } private void button1_Click(object sender, EventArgs e) { // int shi, fen, miao; if (Flag_True == 0) { Flag_True = 1; } else { button1.Text = "肯定"; label6.Text = " "; label7.Text = " "; label5.Text = " "; //label1.Text = "定時關機設置"; Flag_True = 0; } shi = (int)numericUpDown3.Value; fen = (int)numericUpDown2.Value; miao = (int)numericUpDown1.Value; time_set = shi * 3600 + fen * 60 + miao; } private void timer1_Tick(object sender, EventArgs e) { Int32 time_now; Int32 extra; if (Flag_True == 1) { if (DateTime.Now.Minute == fen && DateTime.Now.Hour == shi && DateTime.Now.Second == miao) { button1.Text = "取消"; label6.Text = "剩餘關機時間"; label7.Text = "秒"; label5.Text = "0"; System.Diagnostics.Process.Start("shutdown","-s -t 0");//關機程序 }//shutdown else { time_now = DateTime.Now.Second + DateTime.Now.Minute * 60 + DateTime.Now.Hour * 3600; extra = time_set - time_now; if (extra > 0) { button1.Text = "取消"; label6.Text = "剩餘關機時間"; label7.Text = "秒"; //extra/3600 label5.Text = extra.ToString(); } else { Flag_True = 0; } } } } private void label5_Click(object sender, EventArgs e) { } private void label4_Click(object sender, EventArgs e) { } private void label3_Click(object sender, EventArgs e) { } private void label6_Click(object sender, EventArgs e) { } private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) { this.Visible = true; this.WindowState = FormWindowState.Normal; this.notifyIcon1.Visible = false; } //最小化代碼 private void Form1_SizeChanged(object sender, EventArgs e) { if (this.WindowState == FormWindowState.Minimized) { this.Hide(); this.notifyIcon1.Visible = true; } } } }
界面以下: