Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://blogs.msdn.com/abhinaba/archive/2005/09/12/animation-and-text-in-system-tray-using-c.aspx" rel="noreferrer">Abhinaba Basu's blog post <em>Animation and Text in System tray using C#</em></a> explains.</p> <p>It comes down to:</p> <ul> <li>making an array of icons each of which represent an animation frame. </li> <li>switching the icons in the tray on timer events</li> <li>create a bitmap strip. Each frame is 16x16 pixels </li> <li>use <a href="https://gist.github.com/philoushka/105e5994588e2d054e31#file-gistfile1-cs" rel="noreferrer">SysTray.cs</a></li> </ul> <p>e.g. </p> <p><img src="https://i.stack.imgur.com/jY9vc.jpg" alt="enter image description here"></p> <pre><code>private void button1_Click(object sender, System.EventArgs e) { m_sysTray.StopAnimation(); Bitmap bmp = new Bitmap("tick.bmp"); // the color from the left bottom pixel will be made transparent bmp.MakeTransparent(); m_sysTray.SetAnimationClip(bmp); m_sysTray.StartAnimation(150, 5); } </code></pre> <p><code>SetAnimationClip</code> uses the following code to create the animation frame</p> <pre><code>public void SetAnimationClip (Bitmap bitmapStrip) { m_animationIcons = new Icon[bitmapStrip.Width / 16]; for (int i = 0; i &lt; m_animationIcons.Length; i++) { Rectangle rect = new Rectangle(i*16, 0, 16, 16); Bitmap bmp = bitmapStrip.Clone(rect, bitmapStrip.PixelFormat); m_animationIcons[i] = Icon.FromHandle(bmp.GetHicon()); } } </code></pre> <p>To animate the frame <code>StartAnimation</code> starts a timer and in the timer the icons are changed to animate the whole sequence.</p> <pre><code>public void StartAnimation(int interval, int loopCount) { if(m_animationIcons == null) throw new ApplicationException("Animation clip not set with SetAnimationClip"); m_loopCount = loopCount; m_timer.Interval = interval; m_timer.Start(); } private void m_timer_Tick(object sender, EventArgs e) { if(m_currIndex &lt; m_animationIcons.Length) { m_notifyIcon.Icon = m_animationIcons[m_currIndex]; m_currIndex++; } .... } </code></pre> <p><strong>Using SysTray</strong></p> <p>Create and wire up your menu</p> <pre><code>ContextMenu m_menu = new ContextMenu(); m_menu.MenuItems.Add(0, new MenuItem("Show",new System.EventHandler(Show_Click))); </code></pre> <p>Get an icon you want to show statically in the tray.</p> <p>Create a SysTray object with all the required information</p> <pre><code>m_sysTray = new SysTray("Right click for context menu", new Icon(GetType(),"TrayIcon.ico"), m_menu); </code></pre> <p>Create image strips with the animation frames. For 6 frame strip the image will have a width of 6*16 and height as 16 pixels</p> <pre><code>Bitmap bmp = new Bitmap("tick.bmp"); // the color from the left bottom pixel will be made transparent bmp.MakeTransparent(); m_sysTray.SetAnimationClip(bmp); </code></pre> <p>Start animation indicating how many times you need to loop the animation and the frame delay</p> <pre><code>m_sysTray.StartAnimation(150, 5); </code></pre> <p>To stop animation call</p> <pre><code>m_sysTray.StopAnimation(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload