wpf notifyIcon

private void Initialzie()
{
notifyIcon = new NotifyIcon();
notifyIcon.BalloonTipText = "学生考勤系统";
notifyIcon.Text = "学生考勤系统2";
this.notifyIcon.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Windows.Forms.Application.ExecutablePath);
this.notifyIcon.Visible = false;
//打开菜单项
System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem("打开");
open.Click += new EventHandler(Show);
//退出菜单项
System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("退出");
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);
});
}

private void Show(object sender, EventArgs e)
{
this.Visibility = Visibility.Visible;
this.ShowInTaskbar = true;
this.WindowState = WindowState.Maximized;
this.notifyIcon.Visible = false;
}

 

private void OnMini(string obj)
{
DispatcherHelper.CheckBeginInvokeOnUI(() => {
this.WindowState = WindowState.Minimized;
this.Visibility = Visibility.Collapsed;
this.ShowInTaskbar = false;
notifyIcon.Visible = true;

notifyIcon.ShowBalloonTip(2000);

});
}

 

posted on 2018-02-07 22:55  lixiaofeng6363  阅读(380)  评论(0编辑  收藏  举报