RSS Feed (xml)

Create an Animated System Tray Icon

The .NET Framework makes it easy to show a system tray icon with the NotifyIcon control. You simply need to add this control to a form, supply an icon by setting the Icon property, and, optionally, you can add a linked context menu through the ContextMenu property. The NotifyIcon control automatically displays its context menu when it's right-clicked, unlike most other controls.

You can animate a system tray icon by simply swapping the icon periodically. For example, the following program uses eight icons, each of which shows a moon graphic in a different stage of fullness. By moving from one image to another, the illusion of animation is created.

using System;
using System.Windows.Forms;
using System.Drawing;

public class AnimatedSystemTrayIcon : System.Windows.Forms.Form {

    // (Designer code omitted.)

    Icon[] images;
    int offset = 0;

    private void Form1_Load(object sender, System.EventArgs e) {
        // Load the basic set of eight icons.
        images = new Icon[8];
        images[0] = new Icon("moon01.ico");
        images[1] = new Icon("moon02.ico");
        images[2] = new Icon("moon03.ico");
        images[3] = new Icon("moon04.ico");
        images[4] = new Icon("moon05.ico");
        images[5] = new Icon("moon06.ico");
        images[6] = new Icon("moon07.ico");
        images[7] = new Icon("moon08.ico");

    private void timer_Elapsed(object sender, 
      System.Timers.ElapsedEventArgs e) {
        // Change the icon.
        // This event handler fires once every second (1000 ms).
        notifyIcon.Icon = images[offset];
        if (offset > 7) offset = 0;

Technorati :


  1. There is nothing more redundant which uses more of your time, from one project to the next, than coding how your project is displayed at startup, what is shown during execution, NotifyIcon? Taskbar? When is a Taskbar displayed? During normal Display? When you are minimized? Your Context Menu logic, your exit logic, your deployment logic and your update logic.

    Click here for more detail


Archives In Web World

Fun Mail - Fun in the Mail