【发布时间】:2015-01-31 15:03:37
【问题描述】:
当用户最小化或关闭表单时,我想在系统托盘中添加应用程序。我已经为最小化案例做到了。谁能告诉我,当我关闭表单时,如何让我的应用程序继续运行并将其添加到系统托盘中?
public MainWindow()
{
InitializeComponent();
System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
ni.Icon = new System.Drawing.Icon(Helper.GetImagePath("appIcon.ico"));
ni.Visible = true;
ni.DoubleClick +=
delegate(object sender, EventArgs args)
{
this.Show();
this.WindowState = System.Windows.WindowState.Normal;
};
SetTheme();
}
protected override void OnStateChanged(EventArgs e)
{
if (WindowState == System.Windows.WindowState.Minimized)
this.Hide();
base.OnStateChanged(e);
}
【问题讨论】:
标签: c# wpf system-tray