i am using this:

VB Code:
  1. Imports System.Runtime.InteropServices
  2.  
  3. Module api
  4.  
  5.     Public Result As Boolean
  6.     <StructLayout(LayoutKind.Sequential)> Public Structure NOTIFYICONDATA
  7.         Dim cbSize As Int32
  8.         Dim hwnd As IntPtr
  9.         Dim uID As Int32
  10.         Dim uFlags As Int32
  11.         Dim uCallbackMessage As IntPtr
  12.         Dim hIcon As IntPtr
  13.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Dim szTip As String
  14.         Dim dwState As Int32
  15.         Dim dwStateMask As Int32
  16.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> Dim szInfo As String
  17.         Dim uVersion As Int32
  18.         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> Dim szInfoTitle As String
  19.         Dim dwInfoFlags As Int32
  20.     End Structure
  21.  
  22.     Public Const NIF_MESSAGE As Int32 = &H1
  23.     Public Const NIF_ICON As Int32 = &H2
  24.     Public Const NIF_STATE As Int32 = &H8
  25.     Public Const NIF_INFO As Int32 = &H10
  26.     Public Const NIF_TIP As Int32 = &H4
  27.     Public Const NIM_ADD As Int32 = &H0
  28.     Public Const NIM_MODIFY As Int32 = &H1
  29.     Public Const NIM_DELETE As Int32 = &H2
  30.     Public Const NIM_SETVERSION As Int32 = &H4
  31.     Public Const NOTIFYICON_VERSION As Int32 = &H5
  32.     Public Const NIS_HIDDEN = &H1
  33.     Public Const NIS_SHAREDICON = &H2
  34.     Public Const NIIF_ERROR = &H3
  35.     Public Const NIIF_INFO = &H1
  36.     Public Const NIIF_NONE = &H0
  37.     Public Const NIIF_WARNING = &H2
  38.     Public Const NIM_SETFOCUS = &H4
  39.     Public Const NIIF_GUID = &H5
  40.     Public Declare Function Shell_NotifyIcon Lib "shell32.dll" _
  41.     Alias "Shell_NotifyIconA" (ByVal dwMessage As Int32, _
  42.     ByRef lpData As NOTIFYICONDATA) As Boolean
  43.     Public uNIF As NOTIFYICONDATA
  44.  
  45.     ' Displays a balloon info notification
  46.  
  47.     Public Sub SendBalloonInfoNotification(ByVal strInfo As String)
  48.         With uNIF
  49.             .uFlags = NIF_INFO
  50.             .uVersion = 2000
  51.             .szInfoTitle = "Info"
  52.             .szInfo = strInfo
  53.             .dwInfoFlags = NIIF_INFO
  54.         End With
  55.         Result = Shell_NotifyIcon(NIM_MODIFY, uNIF)
  56.     End Sub
  57.  
  58.     ' Displays a balloon warning notification
  59.  
  60.     Public Sub SendBalloonWarningNotification(ByVal strWarning As String)
  61.         With uNIF
  62.             .uFlags = NIF_INFO
  63.             .uVersion = 2000
  64.             .szInfoTitle = "Warning"
  65.             .szInfo = strWarning
  66.             .dwInfoFlags = NIIF_WARNING
  67.         End With
  68.         Result = Shell_NotifyIcon(NIM_MODIFY, uNIF)
  69.     End Sub
  70.  
  71.     ' Displays a balloon error notification
  72.  
  73.     Public Sub SendBalloonErrorNotification(ByVal strError As String)
  74.         With uNIF
  75.             .uFlags = NIF_INFO
  76.             .uVersion = 2000
  77.             .szInfoTitle = "Error"
  78.             .szInfo = strError
  79.             .dwInfoFlags = NIIF_ERROR
  80.         End With
  81.         Result = Shell_NotifyIcon(NIM_MODIFY, uNIF)
  82.     End Sub
  83.  
  84.     ' Removes the application icon from the system tray
  85.  
  86.     Public Sub RemoveIconFromTray(ByRef frmForm As System.Windows.Forms.Form)
  87.         With uNIF
  88.             .cbSize = Marshal.SizeOf(uNIF)
  89.             .hwnd = frmForm.Handle()
  90.             .uID = 1
  91.         End With
  92.         Shell_NotifyIcon(NIM_DELETE, uNIF)
  93.     End Sub
  94.     ' Adds a application icon to system tray
  95.  
  96.     Public Sub AddIconToTray(ByRef frmForm As System.Windows.Forms.Form)
  97.         With uNIF
  98.             .cbSize = Marshal.SizeOf(uNIF)
  99.             .hwnd = frmForm.Handle
  100.             .uID = 1
  101.             .uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
  102.             .uCallbackMessage = New IntPtr(&H500)
  103.             .uVersion = NOTIFYICON_VERSION
  104.             .hIcon = frmForm.Icon.Handle
  105.         End With
  106.         Result = Shell_NotifyIcon(NIM_ADD, uNIF)
  107.     End Sub
  108.  
  109. End Module

to display an icon on the system tray, on the load event i call:
VB Code:
  1. AddIconToTray(Me)

how can i get the mouse events of the icon that goes to the system tray?


Thank you,
Guilherme Costa