C# Animated System Tray Icon

Notes:
  • You must add the NotifyIcon,a Timer and icons to your project.
  • This code uses 4 ico files which cycle through.
  • The timer increments currentIcon from 0 to 4 and then resets when 4 is reached.

       The number of the variable relates to the icon at that index.

  1. public Form1()  
  2. {  
  3.    InitializeComponent();  
  4.    timer1.Start();  
  5. }  
  6. private Icon[] icons = new Icon[5];  
  7. private int currentIcon = 0;  
  8. private void Form1_Load(object sender, EventArgs e)  
  9. {  
  10.    icons[0] = new Icon("1.ico");  
  11.    icons[1] = new Icon("2.ico");  
  12.    icons[2] = new Icon("3.ico");  
  13.    icons[3] = new Icon("4.ico");  
  14. }  
  15. private void timerIcon_Tick(object sender, EventArgs e)  
  16. {  
  17.    notifyIcon1.Icon = icons[currentIcon];  
  18.    currentIcon++;  
  19.    if (currentIcon == 4)  
  20.    currentIcon = 0;  
  21. }