private void Initialzie() { notifyIcon = new NotifyIcon(); notifyIcon.BalloonTipText = "學生考勤系統"; notifyIcon.Text = "學生考勤系統2"; this.notifyIcon.Icon = S ...
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);
});
}