Click here to Skip to main content
Click here to Skip to main content

Animating Shell Tray Icon With C#

, 18 May 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
This class helps to animate a tray icon.

AppImage.JPG

Tray_Icon.JPG

Introduction

This article explains how to animate the tray icon. In .NET, they have simplified the things to add an icon in the system tray.

While writing an application, in many cases we need to add the application to the system tray and most of the common functionality will be provided from the context menu from the system tray. The application will show background processing through an icon animation, like if the application is processing an event, then it will animate the icon till the event processing is complete.

Background

If you are writing an application in C#, it has the NotifyIcon() component with capabilities to add an application icon in the system tray, or you can use the Shell API Shell_NotifyIcon() to add the icon; using the API is not very easy though.

About the SystemTray Class

This class wraps almost all the functionalities of the NotifyIcon component as well as extends the functionality to achieve easy animation of the tray icon. The class provides functions with which it is easy to configure the class.

SystemTray Class Summary

It is very simple to use this class. I will describe how to use the class after explaining all the other details of the class.

Constructors

Syntax

This class provides four constructors to simplify the use of the class in your project.

//Default constructor
SystemTray()

//Constructor with the parameter tooltip text    
SystemTray(string pTrayText)

//Constructor with tooltip test and icon
SystemTray(string pTrayText, Icon pIcon)

//Constructor with Animation parameter
SystemTray(string pTrayText,Icon pIcon,bool pAnimate) 

Parameter details

  • pTrayText: A string you want to display as the tooltip text when the mouse points at the application system tray icon.
  • pIcon: A System.Drawing.Icon object which will be displayed in the system tray.
  • pAnimate: A bool parameter to support the animation capabilities.

Methods

Syntax

//Start the icon animation
void StartAnimation()

//Stops the icon animation
void StopAnimation()

//Starts the animation with the timeout value after
//which the animation will stop.value will be in miliseconds
void StartAnimation(int timeOut)

//Displays the baloon tooltip with timeout value.
//Time out will be in miliseconds
void ShowBaloonTrayTip(int nTimeout)

//Displays the baloon tooltip with some parameters
void ShowBaloonTrayTip(int nTimeOut,string tipTitle, 
                       string tipText,ToolTipIcon tipIcon)

//Sets the icon objets to the class,will be used for animation
void SetIconRange(object[] IconList)

Properties

//Set icon to class
Icon Icon

//Make tray icon visible true or false
bool Visible

//Set text to trayicon 
string TrayText

//Sets the animation ability 
bool Animate

//To set the baloon tooltip text
string BaloonTipText

//To set the baloon tooltip title
string BalloonTipTitle

//To set the baloon tooltip icon
ToolTipIcon BalloonTipIcon

Using the SystemTray Class

Here is how to use the SystemTray class:

//SystemTray stray;
 
//Add in form load or InitializeComponent() function
          
object[] objValues = new object[2];
objValues[0] = Convert.ToString("Icon1.ico");
objValues[1] = Convert.ToString("Icon2.ico");

//Add Icon

stray= new SystemTray("Sample Tray Icon Animation",null,true);
//Sets icons for animation
stray.SetIconRange(objValues);
//Set menu 
stray.SetContextMenuOrStrip((object)contextMenuStrip1);
//Set Event
stray.DoubleClick += new System.EventHandler(this.DbClick);
//Set menu handler
stray.ContextMenuStrip.Items[0].Click += 
      new EventHandler(SystemTraySample_Click);
//Start icon animation for 2 seconds
stray.StartAnimation(2000);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

sudhir_Kumar
Systems Engineer
India India
No Biography provided

Comments and Discussions

 
GeneralMy vote of 1 PinmemberQ3Vinay1915-Mar-10 3:46 
GeneralIt animates icons in the tray, just as I wanted PinmvpEddy Vluggen11-Mar-10 13:40 
Generalok next step PinmemberDonsw28-Jun-09 14:51 
Generali want the detail Pinmemberyingxuzhong20-Feb-09 0:06 
GeneralThis article doesn't explain anything PinmvpJohn Simmons / outlaw programmer18-May-08 23:46 
How about some discussion of the class being used?
 

"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.1 | Last Updated 19 May 2008
Article Copyright 2008 by sudhir_Kumar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid