Ejemplo n.º 1
0
        /// <summary>
        /// 加载
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            Common.InitWindows(this, ResizeMode.CanMinimize, WindowStartupLocation.CenterScreen);

            #region 托盘初始化
            var notifyIcon = new NotifyIcon();
            AppCache.SetTitle(this.Title);
            notifyIcon.BalloonTipText = AppCache.GetTitle();
            notifyIcon.Text           = AppCache.GetTitle();

            notifyIcon.Icon    = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath);
            notifyIcon.Visible = true;

            //打开菜单项
            var open = new System.Windows.Forms.MenuItem(string.Format("打开{0}", AppCache.GetTitle()));
            open.Click += new EventHandler(Show);

            //退出菜单项
            var exit = new System.Windows.Forms.MenuItem(string.Format("退出{0}", AppCache.GetTitle()));
            exit.Click += new EventHandler(Close);

            //关联托盘控件
            System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { open, exit };
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);

            //双击
            notifyIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler((o, e) => { if (e.Button == MouseButtons.Left)
                                                                                                  {
                                                                                                      this.Show(o, e);
                                                                                                  }
                                                                                      });
            #endregion
        }