自己開發的桌面倒計時小應用,走的是黑白簡約風。(老爸提議我弄個紅色加鞭炮背景的喜慶風= = 嗯,下次再說)
應用截圖
特別說明:標題只能輸入4個字符,可選日期范圍在本機當前日期至距本機當前日期10000天的日期。
涉及到的一些知識點
1.保存修改后的配置
1.選擇項目右鍵-選擇“屬性”
2.在左邊菜單中選擇“設置”,在右邊的表格中填入自己需要保存的屬性的名稱、類型和默認值。
例 名稱:IsBoss; 類型:bool;范圍:用戶; 值:False。
3.在form窗體代碼頁,導入命名空間 : using 項目名稱.Properties
例 你的項目名稱為pro 則導入
using pro.Properties;
4.任意方法中調用該值:
this.checkBox1.Checked = Settings.Default.IsBoss;
5.在窗體的FormClosing方法中保存此值:
Settings.Default.IsBoss = this.checkBox1.Checked;
Settings.Default.Save(); //這句一定不能少
6.OK,這樣就行了。
2.委托的簡易使用(看原理有點暈,搜索到了這個方法,實現了效果)
資料來源http://www.cnblogs.com/pfcan66/archive/2012/09/12/2680596.html
在項目中的使用
1.點擊窗體1【FrmMain】的修改按鈕【btnUpdate】打開窗體2【FrmModify】
2.點擊窗體2【FrmModify】的保存按鈕【btnSave】關閉窗體2【FrmModify】,刷新窗體1【FrmMain】
窗體1【FrmMain】
//"修改"按鈕點擊事件 private void btnUpdate_Click(object sender, EventArgs e) { FrmModify frmModify= new FrmModify(); frmModify.getHandler = load;//將方法賦給委托對象 frmModify.ShowDialog(); } //加載事件 private void load() { //方法 }
窗體2【FrmModify】
public delegate void GetHandler();//聲明委托 public GetHandler getHandler; private void btnSave_Click(object sender, EventArgs e) { if (getHandler != null) { //其他操作 getHandler(); } }
3.獲取日歷控件MonthCalendar的選擇日期
private void monthCalendar_MouseDown(object sender, MouseEventArgs e) { MonthCalendar.HitTestInfo hitInfo = monthCalendar.HitTest(e.Location); if (hitInfo.HitArea == MonthCalendar.HitArea.Date)//當選擇了日期后 { txtCalendar.Text = monthCalendar.SelectionStart.ToString("yyyy-MM-dd"); } }
更多資料-MonthCalendar的mousedown方法獲得選擇日期
http://www.cnblogs.com/IT-Bear/archive/2013/01/23/2872504.html
4.透明效果“將Form的backColor設置為某色,修改transparencyKey為某色” Opacity 設置透明度(某色最好不要是背景圖片的顏色、控件的背景色)
5.開機自啟動
資料來源 :http://www.cnblogs.com/hb_cattle/articles/1553090.html
private void AutoMenu_Click(object sender, EventArgs e) { string strName = Application.ExecutablePath; string strnewName = strName.Substring(strName.LastIndexOf("\\") + 1); if (AutoMenu.Checked) { //修改注冊表,使程序開機時不自動執行。 this.AutoMenu.Checked = false; Microsoft.Win32.RegistryKey Rkey
= Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); Rkey.DeleteValue(strnewName, false); MessageBox.Show("程序設置完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { this.AutoMenu.Checked = true; if (!File.Exists(strName))//指定文件是否存在 return; Microsoft.Win32.RegistryKey Rkey
= Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); if (Rkey == null) Rkey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); Rkey.SetValue(strnewName, strName);//修改注冊表,使程序開機時自動執行。 MessageBox.Show("程序設置完成,重新啟動計算機后即可生效!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
6.發布exe的步驟


題外話:自己做小應用就是一個享受與學習的過程。
相關資料