Results 1 to 6 of 6

Thread: How to Place Your C# Application in the System Tray?

  1. #1
    Join Date
    Aug 2006
    Posts
    173

    How to Place Your C# Application in the System Tray?

    Can we place the C# Application in the System Tray?? I am trying to do lot of things but not getting succeeded. Does anyone know the steps that are involved in specifying that an application is to be minimized to the Tray.?? Also how to allow the user to restore the application by double-clicking the icon. Since I am new to the C# the detailed information will be most welcomed. Please help me solving the problem as soon as possible.
    "Let us remember that our interest is in concord, not conflict, and that our real eminence rests in the victories of peace, not those of war." -McKinley

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: How to Place Your C# Application in the System Tray?

    If you want to place your C# Application in the System Tray, then you will have to use an event handler for the form's Resize event. Using this event handler for Resize event will hide the application when it's minimized. After doing this it will not appear on the task bar. The following coding can be useful for doing that :
    Code:
    private void Form1_Resize(object sender, System.EventArgs ea)
    {
       if (FormWindowState.Minimized == WindowState)
          Hide();
    }

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to Place Your C# Application in the System Tray?

    As you said that you are new for the C# application, here is the Step-by-step process for placing the C# application in the System Tray :
    1. You can create or open the C# windows form.
    2. Then open the Visual Studio Toolbox.
    3. In that you will find the NotifyIcon. Drag a NotifyIcon control onto the form.
    4. By default the control will named notifyIcon1 and will be placed below the form because it has no visual representation on the form itself.
    5. You will have to set the NotifyIcon control's Text property to the name you want to appear when the user pauses the mouse over the application's icon.
    6. Also you will have to set the control's Icon property to the icon that you want to appear in the System Tray.
    7. Then add the coding for the event handler for the form's Resize event as mentioned by the 'opaper'.
    8. After that add an event handler for the NotifyIcon.DoubleClick event. By doing this the application will be restored when the icon is double-clicked.
    Here is the coding for that :
    Code:
    private void notifyIcon1_DoubleClick(object sender,
                                         System.EventArgs ea)
    {
        Show();
        WindowState = FormWindowState.Normal;
    }
    Hope that these steps will help you to fix your problem.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to Place Your C# Application in the System Tray?

    You will also have to check the steps that is involved with adding a context menu to the icon :
    1. Drag a ContextMenu control onto the form, from the Visual Studio Toolbox.
    2. Then select the Edit Menu option by right clicking on the ContextMenu control.
    3. Type the text that you want to appear in your context menu. Options such as Restore and Close Application can be used in this text.
    4. Then double-click the menu item to create and code each item's handler, as normally you do with any menu. Like for the Close Application menu item; simply call the form's Close method.
    5. Lastly set the NotifyIcon control's ContextMenu property to the new context menu you just created by selecting the menu from the drop-down list.

  5. #5
    Join Date
    Mar 2008
    Posts
    349

    Re: How to Place Your C# Application in the System Tray?

    Sometimes you will have to do something more for the notifyIcon1_DoubleClick like this :
    Show();
    WindowState = FormWindowState.Normal;
    Activate();
    You can also add a form closing event to your form like this one :
    Code:
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
    RestoreIcon.Visible = false;
    }
    The icon will be erased when your form is closing.

  6. #6
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How to Place Your C# Application in the System Tray?

    I think that you will have to create an icon first. You can use the Favicon Generator for creating the icons. Looks of an icons are not important, so make it anyway. You can place that icon anywhere and for that you will have to edit the path so that it suits your needs. Here is the code for that :
    Code:
     namespace SystemTrayTest    
    {    
    public partial class Form1 : Form    
    {    
     public NotifyIcon notifyIcon1 = new NotifyIcon();         
       public Form1()    
     {    
     InitializeComponent();    
    }    
    private void Form1_Resize(object sender, EventArgs e)    
    {      
     if (this.WindowState == FormWindowState.Minimized)    
     {    
     this.ShowInTaskbar = false;    
     this.WindowState = FormWindowState.Minimized;    
    this.notifyIcon1.Visible = true;    
    this.notifyIcon1.Text = "KlausurServer v 2.1";    
    }    
    }       
    private void Form1_Load(object sender, EventArgs e)    
     {    
    this.notifyIcon1 = new NotifyIcon();    
    this.notifyIcon1.Visible = false;    
     try    
     {    
      notifyIcon1.Icon = new System.Drawing.Icon(@"D:\klausurServer.ico");    
                this.notifyIcon1.Click += new System.EventHandler(notifyIcon1_Click);    
        }    
      catch (Exception ee)    
    {    
                  Console.WriteLine(ee.Message);    
    }    
     }    
    
     private void notifyIcon1_Click(object sender, System.EventArgs e)    
    {    
    this.ShowInTaskbar = true;    
    this.notifyIcon1.Visible = false;    
     this.WindowState = FormWindowState.Normal;    
     }    
    }    
    }

Similar Threads

  1. System slow down with gray bitdefender system tray icon
    By Jigya L. in forum Networking & Security
    Replies: 4
    Last Post: 18-02-2011, 07:40 PM
  2. Minimizing to System Tray
    By Rising in forum Windows Vista Mail
    Replies: 2
    Last Post: 12-04-2010, 04:33 AM
  3. How to use the System Tray in Java?
    By - Empty Shell - in forum Software Development
    Replies: 4
    Last Post: 16-02-2010, 04:50 AM
  4. Tray 2.5 application not able to work under Windows 7
    By Sawan123 in forum Operating Systems
    Replies: 5
    Last Post: 13-02-2010, 05:05 AM
  5. pc tools tray application
    By Anthony in forum Vista Help
    Replies: 4
    Last Post: 21-09-2007, 08:20 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,659,957.90801 seconds with 17 queries