1

I have made a notifyicon in my application but i want to make it tray in system stray when application closes anyone knows how to fix this? Thank You. (Used c# if you need to know)

And is it possible to make when the windows starts the application start as a tray?

Osayed
  • 43
  • 6
  • check this out it may help: [C# Minimize to system tray on close](http://stackoverflow.com/questions/13625069/c-sharp-minimize-to-system-tray-on-close) – user45 Oct 23 '16 at 19:08
  • An icon in the notification area has an inseparable relationship with a window, that it needs for communication. Consequently, the icon cannot exist by itself. What you are asking for is not possible. You'll have to implement custom logic that hides your application window, when the user clicks the close button. – IInspectable Oct 23 '16 at 21:13

2 Answers2

0

Take a look at this question's answers:

Handle the form’s Resize event. In this handler, you override the basic functionality of the Resize event to make the form minimize to the system tray and not to the taskbar. This can be done by doing the following in your form’s Resize event handler: Check whether the form’s WindowState property is set to FormWindowState.Minimized. If yes, hide your form, enable the NotifyIcon object, and show the balloon tip that shows some information. Once the WindowState becomes FormWindowState.Normal, disable the NotifyIcon object by setting its Visible property to false. Now, you want the window to reappear when you double click on the NotifyIcon object in the taskbar. For this, handle the NotifyIcon’s MouseDoubleClick event. Here, you show the form using the Show() method.

Making it start in the tray shouldn't be much more than this, and try overriding the Closing event to do it when the window's closing

Community
  • 1
  • 1
Pluriscient
  • 125
  • 1
  • 10
  • Thank you, about it starting with tray worked, but i still don't know how to make the tray stay in system untill they right click it and click "Exit"? – Osayed Oct 23 '16 at 18:38
  • You can close any application with `Environment.Exit(0)`, can you insert that on the exit handling? – Pluriscient Oct 23 '16 at 18:50
0

Change the ShowInTaskbar Property to False in the startup Form And the windowsState to Minimized so it will be unvisible

It worked Fine with me

Form Properties Window

this is the code i writen:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{

    bool m_CloseApp = false;
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {if (m_CloseApp == false) { 
       e.Cancel = true;
    this.WindowState = FormWindowState.Minimized;
    }
    }

    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    {
        m_CloseApp = true;
        this.Close();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
        this.WindowState = FormWindowState.Minimized;
    }
}
}

When user close the Form the application will not Exit, but when he hit the Exit button from the ContextMenuStrip of the notifyIcon the application will be closed

Hadi
  • 36,233
  • 13
  • 65
  • 124