Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



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

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 21-01-2010
pushpendra's Avatar
Member
 
Join Date: Aug 2006
Posts: 95
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
Reply With Quote
  #2  
Old 21-01-2010
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
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();
}
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #3  
Old 21-01-2010
Modifier's Avatar
Member
 
Join Date: Jan 2008
Posts: 1,502
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.
Reply With Quote
  #4  
Old 21-01-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
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.
Reply With Quote
  #5  
Old 21-01-2010
Warner's Avatar
Member
 
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.
Reply With Quote
  #6  
Old 21-01-2010
Member
 
Join Date: Nov 2008
Posts: 1,193
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;    
 }    
}    
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Place Your C# Application in the System Tray?"
Thread Thread Starter Forum Replies Last Post
System slow down with gray bitdefender system tray icon Jigya L. Networking & Security 4 18-02-2011 07:40 PM
How to use the System Tray in Java? - Empty Shell - Software Development 4 16-02-2010 04:50 AM
Tray 2.5 application not able to work under Windows 7 Sawan123 Operating Systems 5 13-02-2010 05:05 AM
pc tools tray application Anthony Vista Help 4 21-09-2007 09:20 PM
System Tray Icons MyD0j0 Windows XP Support 8 11-05-2007 07:59 AM


All times are GMT +5.5. The time now is 12:10 PM.