How about a solution like this:
Public Class BalloonNotifier
Public Shared Sub ShowInfoBalloon(ByVal title As String, ByVal text As String)
Dim ni As NotifyIcon = CreateNotification()
ni.Icon = SystemIcons.Exclamation
ShowBalloon(ni, title, text)
End Sub
Public Shared Sub ShowFailBalloon(ByVal title As String, ByVal text As String)
Dim ni As NotifyIcon = CreateNotification()
ni.Icon = SystemIcons.Error
ShowBalloon(ni, title, text)
End Sub
' helper to create a new NotifyIcon
Private Shared Function CreateNotification() As NotifyIcon
Dim notifyIcon As NotifyIcon = New NotifyIcon()
notifyIcon.Visible = True
' assuming you want to handle both the balloon being clicked and the icon that remains in the tray.
AddHandler notifyIcon.BalloonTipClicked, AddressOf BalloonTipClicked
AddHandler notifyIcon.Click, AddressOf BalloonTipClicked
Return notifyIcon
End Function
Private Shared Sub BalloonTipClicked(sender As Object, e As EventArgs)
Dim notifyIcon As NotifyIcon = sender
MessageBox.Show(String.Format("Clicked on Notifier for document ""{0}""", notifyIcon.BalloonTipText))
' lets hide the balloon and its icon after click
notifyIcon.Visible = False
notifyIcon.BalloonTipIcon = Nothing
notifyIcon.Dispose()
End Sub
Private Shared Sub ShowBalloon(ByRef notifyicon As NotifyIcon, ByVal title As String, ByVal text As String)
notifyicon.Visible = True
notifyicon.BalloonTipText = text
notifyicon.BalloonTipTitle = title
notifyicon.ShowBalloonTip(5000)
End Sub
End Class
Then in your Form or wherever:
' delegates with parameters
Delegate Sub OnDocumentSucceeded(ByVal notification As String, ByVal filename As String)
Delegate Sub OnDocumentFailed(ByVal notification As String, ByVal filename As String)
Public Sub DocumentSucceeded(ByVal filename As String)
' notify success
Invoke(New OnDocumentSucceeded(AddressOf BalloonNotifier.ShowInfoBalloon), "Your file was created!", filename)
End Sub
Public Sub DocumentFailed(ByVal filename As String)
' notify fail
Invoke(New OnDocumentSucceeded(AddressOf BalloonNotifier.ShowFailBalloon), "Creating document failed!", filename)
End Sub