C# .NET - how to add application icon to the task bar

Asked By aman on 19-Aug-11 02:07 AM
hi all,

i have completed my windows application and one of my requirement is to add the application icon to the task bar.

i have searched this thing on google unable to find any good article to make me understand the concept.

so i request you all to please help me with some good example, so that i can make use of it....

Thanks and Regards
Aman Khan
Web Star replied to aman on 19-Aug-11 02:09 AM
Windows Forms http://msdn.microsoft.com/en-us/library/aa984200(v=vs.71).aspx component displays a single icon in the status notification area of the taskbar.
http://msdn.microsoft.com/en-us/library/aa984250(v=vs.71).aspx
Ravi S replied to aman on 19-Aug-11 02:09 AM
HI

To set the icon

  1. Assign a value to the Icon property. The value must be of type System.Drawing.Icon and can be loaded from an .ico file. You can specify the icon file in code or by clicking the ellipsis button (VisualStudioEllipsesButton screenshot) next to the Icon property in the Properties window, and then selecting the file in the Open dialog box that appears.

  2. Set the http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.visible%28v=vs.80%29.aspx property to true.

  3. Set the http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.text%28v=vs.80%29.aspx property to an appropriate ToolTip string.

    In the following code example, the path set for the location of the icon is the My Documents folder. This location is used because you can assume that most computers running the Windows operating system will include this folder. Choosing this location also enables users with minimal system access levels to safely run the application. The following example requires a form with a NotifyIcon control already added. It also requires an icon file named Icon.ico.

    [Visual Basic]

    ' You should replace the bold icon in the sample below
    ' with an icon of your own choosing.
    NotifyIcon1.Icon = New _ 
       System.Drawing.Icon(System.Environment.GetFolderPath _
       (System.Environment.SpecialFolder.Personal) _
       & "\Icon.ico")
    NotifyIcon1.Visible = True
    NotifyIcon1.Text = "Antivirus program"
    
    

    [C#]

    // You should replace the bold icon in the sample below
    // with an icon of your own choosing.
    // Note the escape character used (@) when specifying the path.
    notifyIcon1.Icon = 
       new System.Drawing.Icon (System.Environment.GetFolderPath
       (System.Environment.SpecialFolder.Personal)
       + @"\Icon.ico");
    notifyIcon1.Visible = true;
    notifyIcon1.Text = "Antivirus program";
    
    

    [cpp]

    // You should replace the bold icon in the sample below
    // with an icon of your own choosing.
    notifyIcon1->Icon = gcnew 
       System::Drawing::Icon(String::Concat
       (System::Environment::GetFolderPath
       (System::Environment::SpecialFolder::Personal),
       "\\Icon.ico"));
    notifyIcon1->Visible = true;
    notifyIcon1->Text = "Antivirus program";
    

refer
http://msdn.microsoft.com/en-us/library/062478za%28v=vs.80%29.aspx
Ravi S replied to aman on 19-Aug-11 02:10 AM
HI

Add Display Icon to Taskbar

1. Right-click the Desktop and select "Properties..." from the menu that appears.

2. Click the "Settings" tab.

3. Click the "Advanced..." button.

4. Check the "Show settings icon on task bar" check box.

5. Click Apply.

6. Click OK.

7. Click OK.

8. The Display icon will now be displayed in the Taskbar (next to the clock).
To open the Display properties window, just double-click this icon.

refer
http://www.computertim.com/howto/article.php?topic=windows&idn=65
Anoop S replied to aman on 19-Aug-11 02:59 AM

The Old way:

The basic steps to using a tray icon via the windows API are:

  1. Load up the NOTIFYICONDATA structure
  2. Call Shell_NotifyIcon(NIM_ADD, &MyTrayNotifyStruct)

Changing the values of the fields in NOTIFYICONDATA and calling Shell_NotifyIcon allows you to change to icon or tool tip text or remove the icon itelf. All this messing around has been bundled in a class wrapper to make it easier and neater.

The Better way

The simpler way to add an icon to the system tray is to create an object of type CSystemTray either as a member variable or dynamically. Two forms of the constructor allow the programmer to insert the icon into the tray as the CSystemTray object is created, or by using the member function CSystemTray::Create. eg.

	CSystemTray m_TrayIcon;   // Member variable of some class

	...
	// in some member function maybe...
	m_TrayIcon.Create(pParentWnd, WM_MY_NOTIFY, "Click here",
	                  hIcon, nTrayIconID);

This will insert an icon in the system tray. See the following section for details.

http://www.codeguru.com/Cpp/COM-Tech/shell/icons/article.php/c1335

check out example here

http://www.codeguru.com/csharp/.net/net_general/tipstricks/article.php/c6933/

http://msdn.microsoft.com/coding4fun/windows/utility/article.aspx?articleid=908744

Jitendra Faye replied to aman on 19-Aug-11 03:12 AM
The Windows Forms NotifyIcon component displays a single icon in the status notification area of the taskbar.

To display multiple icons in the status area, you must have multiple NotifyIcon components on your form. To set the icon displayed for a control, use the Icon property. You can also write code in the DoubleClick event handler so that something happens when the user double-clicks the icon. For example, you could make a dialog box appear for the user to configure the background process represented by the icon.


Example-

// You should replace the bold icon in the sample below
// with an icon of your own choosing.
// Note the escape character used (@) when specifying the path.
notifyIcon1.Icon = 
   new System.Drawing.Icon (System.Environment.GetFolderPath
   (System.Environment.SpecialFolder.Personal)
   + @"\Icon.ico");
notifyIcon1.Visible = true;
notifyIcon1.Text = "Antivirus program";

Follow this link for more detail-
http://msdn.microsoft.com/en-us/library/062478za.aspx
Hope this will help you.
dipa ahuja replied to aman on 19-Aug-11 04:16 AM
string s = "Sachin Kumar Singh";
 
string[] name = s.Split(' ');
 
string ShortName = name[0][0] + ". ";
ShortName += name[1][0] + ". " ;
ShortName += name[2].ToString();
 
Response.Write("Name: " + ShortName); //Return S. K. Singh
dipa ahuja replied to aman on 19-Aug-11 04:50 AM
Follow the steps

1. Add NotifyIcon and ContexMenuStrip from the toolBox to the window Form

2. Set the following properties of the NotifyIcon from the property window:


3. Take a Button and write the code in its click event
private void button1_Click(object sender, EventArgs e)
{
  //display menustrip     
  notifyIcon1.ShowBalloonTip(1);
 
  //hide form     
  this.Visible = false;
}
4. Add a menu item in ContenxMenuStip : Close and add the click event of menu item this way:

private void CloseToolStripMenuItem_Click(object sender, EventArgs e)
{
  //hide menustrip
  notifyIcon1.Visible = false;
  
  //display form
  this.Show();
}