1. 禁止多個進程運行,並當重複運行時啟動以前的進程
2. 以主表單為主要頁面, 登入表單僅為次表單
3. 含有縮小到工具列的功能
 using System;
using System;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
namespace ICMD
{
    public partial class frmMain : Form
    {
        /// <summary>
        /// 應用程式名稱
        /// </summary>
        private string _applicationName = string.Empty;
        #region -- Public Methods --
        public frmMain(string applicationName)
        {
            InitializeComponent();
            // 儲存傳入的應用程式名稱
            _applicationName = applicationName;
            //呼叫登入Form
            frmLogin fl = new frmLogin();
            fl.ShowDialog();
            if (fl.DialogResult.Equals(DialogResult.OK))
            {
                fl.Close();
                Application.Run(new frmMain(_applicationName));
            }
        } 
        #endregion
        #region -- Private Methods --
        private void frmMain_Load(object sender, EventArgs e)
        {            
            // 設置標題
            this.Text = _applicationName;
        }
        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            //notifyIcon1.Dispose();
            //Application.Exit();
            if (MessageBox.Show("尚有作業進行中,仍要結束本系統嗎?", "系統結束",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                    MessageBoxDefaultButton.Button2) == DialogResult.No)
            {
                e.Cancel = true;
            }
            else
            {
                this.notifyIcon1.Visible = false; //Notify Icon圖示隱藏
                this.notifyIcon1.Dispose(); //移除notifyicon
                notifyIcon1.Icon = null;
                Application.DoEvents();
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            #region 轉換顯示民國年
            CultureInfo cuinfo = new System.Globalization.CultureInfo("zh-TW"); // 自訂 CultureInfo 文化物件。
            cuinfo.DateTimeFormat.Calendar = cuinfo.OptionalCalendars[1]; //取得可為文化特性所使用的曆法清單。
            #endregion
            //設定狀態列信息
            Tssl_Lb_Sysname.Text = "歡迎使用維運申告系統!";
            Tssl_Lb_Time.Text = "目前時間: "  DateTime.Now.ToString("yyy年MM月dd日HH時mm分ss秒", cuinfo);
            
            Tssl_Lb_User.Text = "目前使用者: admin";
        }
        #endregion
#region -- Event Handle --
        private void notifyIcon1_DoubleClick(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)
            {
                //this.Show();
                this.ShowInTaskbar = true; // 顯示在系統任務欄
                this.WindowState = FormWindowState.Normal; // 還原視窗
                this.notifyIcon1.Visible = false; //Notify Icon圖示隱藏
            }
        }
        private void frmMain_SizeChanged(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Minimized)  // 目前視窗是否為最小化
            {
                this.ShowInTaskbar = false; // 不顯示在系統任務欄               
                this.notifyIcon1.Visible = true; //Notify Icon圖示顯示
                //this.Hide();
            }
        }
        #endregion
    }
}

 
  
					
				
评论