ARTICLE

Animating System Tray in VB.NET

Posted by K Niranjan Kumar Articles | Visual Basic 2010 September 05, 2003
I am sure those who have worked with Visual C++ would have experienced the problem of displaying an icon in system tray and manipulating with context menus for that. This application gives you a picture of how to use .NET's TrayIcon class.
Download Files:
 
Reader Level:

Description.

I am sure those who have worked with Visual C++ would have experienced the problem of displaying an icon in system tray and manipulating with context menus for that. Previously I use to display System tray icons with Shell_NotifyIcon by filling a structure and manipulating with a context menu for that icon is another problem. We need to create a menu dynamically and call TrackPopMenu and call DestroyMenu().

This application gives you a picture of how to use .NET's TrayIcon class. With the introduction of this class in .NET, no need to call Shell_NotifyIcon Win32 API and TrackPopMenu() and DestroyMenu() APIs. Designing of your icon, creating context menu, adding event handlers are all done during design time itself. The complete source code is available in AnimateTray.zip file.

Source Code:

Public Sub AnimateIcon(sender As Object, e As System.EventArgs)
If Not (m_Icon1 Is Nothing) And Not (m_Icon2 Is Nothing) Then
If
m_bIconFlag = True Then
m_trayIcon.Icon = m_Icon2
m_bIconFlag =
False
Else
m_trayIcon.Icon = m_Icon1
m_bIconFlag =
True
End
If
End
If
End
Sub 'AnimateIcon
' Start menu handler
Protected Sub OnClickStop(sender As Object, e As System.EventArgs)m_timer.Start()
menuItem4.Enabled =
True
menuItem1.Enabled = False
End Sub 'OnClickStop
' Stop menu handler
Protected Sub OnClickStop(sender As Object, e As System.EventArgs)
m_timer.Stop()
menuItem4.Enabled =
False
menuItem1.Enabled = True
End
Sub 'OnClickStop

Clicking the right mouse button on the system tray icon, a menu is populated. Selecting Start option from the menu will create a timer. This timer object is associated with AnimateIcon() function. m_Icon1 and m_Icon2 are which are associated with Icon1.ico and Icon2.ico files resp .The two icon files Icon1.ico and Icon2.ico should exist in the same directory.

share this article :
post comment
 

Can you tell me how to modify this app so that the initial window is not displayed?

Posted by Bill Buss Apr 16, 2009
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor