-2

我创建了一个 WPF 应用程序。它有一个窗口,它隐藏在关闭按钮上。但我想在通知栏中显示它。当用户点击它时,应该显示窗口。

这是我的代码:

public MainWindow()
{
    InitializeComponent();
    System.Timers.Timer aTimer = new System.Timers.Timer();
    aTimer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);
    aTimer.Interval = 3000;
    aTimer.Enabled = true;

}

private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    lblProcess.Content = "Test Window"

}

// minimize to system tray when applicaiton is closed
protected override void OnClosing(CancelEventArgs e)
{
    // setting cancel to true will cancel the close request
    // so the application is not closed
    e.Cancel = true;

    this.Hide();
    //this.Show();

    base.OnClosing(e);
}

我已经读过这个:create-popup-toaster-notifications-in-windows-with-net

最小化应用程序到系统托盘使用 wpf-not-using-notifyicon

使用 wpf 最小化关闭应用程序到系统托盘

但没有得到你我怎么能这样做?

任何帮助表示赞赏!

4

1 回答 1

2

我已经使用了这段代码:

System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
ni.Icon = new System.Drawing.Icon("D:\\images.ico");
ni.Visible = true;
ni.DoubleClick +=delegate(object sender, EventArgs args)
               {
                  this.Show();
                  this.WindowState = WindowState.Normal;
               };
于 2016-09-28T13:01:17.353 回答