示例#1
0
 private void InitializTrayIcon()
 {
     this.Visibility = Visibility.Hidden;
     _notifyIcon     = new SWF.NotifyIcon
     {
         //BalloonTipText = "万年历程序运行中...";
         Text    = GetFullDateDesc(DateTime.Now, true),
         Visible = true,
         //重要提示:此处的图标图片在resouces文件夹。可是打包后安装发现无法获取路径,导致程序死机。建议复制一份resouces文件到UI层的bin目录下,确保万无一失。
         Icon = new System.Drawing.Icon(Application.GetResourceStream(new Uri($"images/cal{DateTime.Now:dd}.ico", UriKind.Relative)).Stream)
     };
     //_notifyIcon.ShowBalloonTip(1000);//托盘气泡显示时间
     //双击事件
     _notifyIcon.MouseDoubleClick -= NotifyIcon_MouseClick;
     _notifyIcon.MouseDoubleClick += NotifyIcon_MouseClick;
     //鼠标点击事件
     _notifyIcon.MouseClick -= NotifyIcon_MouseClick;
     _notifyIcon.MouseClick += NotifyIcon_MouseClick;
     //右键弹出式菜单
     SWF.ContextMenuStrip notifyContextMenu = new SWF.ContextMenuStrip();
     _muiShow = new SWF.ToolStripMenuItem("显示日历窗口", new System.Drawing.Bitmap(Application.GetResourceStream(new Uri($"images/screen.png", UriKind.Relative)).Stream), ShowMenuItem_Click);
     SWF.ToolStripMenuItem muiAutoStartNextTime = new SWF.ToolStripMenuItem("下次自动启动")
     {
         Checked      = AutoManageHelper.IsMeAutoStart(),
         CheckOnClick = true
     };
     muiAutoStartNextTime.Click -= MuiAutoStartNextTime_Click;
     muiAutoStartNextTime.Click += MuiAutoStartNextTime_Click;
     SWF.ToolStripMenuItem muiAbout = new SWF.ToolStripMenuItem("关于...");
     SWF.ToolStripMenuItem muiExit  = new SWF.ToolStripMenuItem("退出", new System.Drawing.Bitmap(Application.GetResourceStream(new Uri($"images/exit.png", UriKind.Relative)).Stream), ExitMenuItem_Click);
     notifyContextMenu.Items.AddRange(new SWF.ToolStripItem[] { _muiShow, muiAutoStartNextTime, muiAbout, new SWF.ToolStripSeparator(), muiExit });
     //关联托盘控件
     _notifyIcon.ContextMenuStrip = notifyContextMenu;
     //时钟按秒
     _timer = new Timer(new TimerCallback(ResetTrayIcon));
     _timer.Change(0, 1000);
 }
示例#2
0
 private void MuiAutoStartNextTime_Click(object sender, EventArgs e)
 {
     SWF.ToolStripMenuItem mi = sender as SWF.ToolStripMenuItem;
     AutoManageHelper.SetMeStart(mi.Checked);
 }