-2

I've created one WPF application. It has one window and it's hide on close button. But i want to show it in notification-bar. and when user click on that then windows should display.

Here is my code:

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);
}

I've already read this: create-popup-toaster-notifications-in-windows-with-net

And minimizing-application-to-system-tray-using-wpf-not-using-notifyicon

minimizing-closing-application-to-system-tray-using-wpf

But didn't get you how can i do this?

Any help appreciated!

Community
  • 1
  • 1
Barry Allen
  • 81
  • 2
  • 14
  • 1
    Possible duplicate of [Minimizing/Closing Application to system tray using WPF](http://stackoverflow.com/questions/27265139/minimizing-closing-application-to-system-tray-using-wpf) – Manfred Radlwimmer Sep 28 '16 at 08:58
  • @ManfredRadlwimmer, Have to read my question? Please read it first. I want to show this in notification – Barry Allen Sep 28 '16 at 09:01
  • Yes, I read your question. The posts you linked yourself contain all the info you need. If you have further questions to the answers you already read - you can add a comment (when you have enough reputation) to the original answer and ask for clarification. Since you didn't include the required [MCVE] we can't help you any further than you already managed to get. – Manfred Radlwimmer Sep 28 '16 at 09:04
  • @ManfredRadlwimmer, It's about to hide window, that i did, **I WANT IN NOTIFICATION** – Barry Allen Sep 28 '16 at 09:07
  • check this: https://ebbypeter.wordpress.com/2010/06/28/minimize-a-wpf-application-to-system-tray-in-c/ – Felix D. Sep 28 '16 at 09:07
  • @Motivated, Thanks for the link – Barry Allen Sep 28 '16 at 09:10
  • @user6689472 Then you should clarify your question. "I WANT IN NOTIFICATION" - what do you want in the notification? Your code simply contains a `ListProcesses();`. What is it you want to show? "But i want to show it in notification-bar.". Rephrase your question to make sense and someone might be able to help you. – Manfred Radlwimmer Sep 28 '16 at 09:21
  • Dear @ManfredRadlwimmer if you read the question carefully then must read this line **. It has one window and it's hide on close button. But i want to show it in notification-bar.** this is a second sentence of my question. – Barry Allen Sep 28 '16 at 09:24
  • *Rephrase your question to make sense and someone might be able to help you* It's make sense if you take a few minutes and read it, instead of just flag it to duplicate or down vote! – Barry Allen Sep 28 '16 at 09:28
  • @ManfredRadlwimmer, Are you there? Now do you have any idea? – Barry Allen Sep 28 '16 at 11:41
  • I still don't understand your question. The way it is phrased it sounds like you want to show the window in the taskbar (which wouldn't fit, for obvious reasons). I get the part, that you want to hide the window instead of closing it, but you said you already do that. – Manfred Radlwimmer Sep 28 '16 at 12:25

1 Answers1

2

I have done using this code:

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;
               };
Barry Allen
  • 81
  • 2
  • 14