有人能告诉我为什么这段代码中的onclick事件不工作吗?其他的都没问题。只有onclick事件不是!另外,我如何传递fileName才能像这样使用它:
BalloonTipText=FileName代码:
Delegate Sub InvokeDelegate()
Public Sub OnDocumentSucceeded(fileName As String)
If Not Me.IsHandleCreated Then
Me.CreateHandle()
End If
Invoke(New InvokeDelegate(AddressOf Handle_OnDocumentSucceeded))
End Sub
Public Sub Handle_OnDocumentSucceeded()
NotifyIcon1.Icon = SystemIcons.Exclamation
NotifyIcon1.BalloonTipTitle = "Your document has been generated"
'NotifyIcon1.BalloonTipText = fileName
NotifyIcon1.BalloonTipText = "testing...."
NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(5000)
End Sub
Private Sub NotifyIcon1_MouseClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon1.MouseClick
MessageBox.Show("Text clicked")
'This is not working!!!
End Sub发布于 2015-07-14 22:37:16
如何传递fileName才能像这样使用:
BalloonTipText=FileName
Public Delegate Sub InvokeDelegate(ByVal strFileName As String) 'Create delegate where you can pass the file name in.
Public WithEvents NotifyIcon1 As New NotifyIcon 'I didn't drop it on my form... Also if you do this you wont have to handle any handlers.
Public Sub OnDocumentSucceeded(fileName As String)
If Not Me.IsHandleCreated Then
Me.CreateHandle()
End If
Invoke(New InvokeDelegate(AddressOf Handle_OnDocumentSucceeded), fileName)
End Sub
Public Sub Handle_OnDocumentSucceeded(ByVal strName As String)
NotifyIcon1.Icon = SystemIcons.Exclamation
NotifyIcon1.BalloonTipTitle = "Your document has been generated"
NotifyIcon1.BalloonTipText = strName
NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
NotifyIcon1.Visible = True
NotifyIcon1.ShowBalloonTip(5000)
End Sub
Private Sub NotifyIcon1_BalloonTipClicked(sender As Object, e As System.EventArgs) Handles NotifyIcon1.BalloonTipClicked
MessageBox.Show("Text clicked")
End Sub
Private Sub NotifyIcon1_Click(sender As Object, e As System.EventArgs) Handles NotifyIcon1.Click
MessageBox.Show("Notify clicked")
End Sub这也已经尝试和测试过了。我不确定您是否将控件拖放到窗体上。在我的示例中,我创建了一个创建NotifyIcon的新变量Public WithEvents NotifyIcon1...。
编辑
我注意到您使用的签名是错误的...
Private Sub NotifyIcon1_MouseClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon1.MouseClick
MessageBox.Show("Text clicked")
'This is not working!!!
End Sub应该是..。
Private Sub NotifyIcon1_Click(sender As Object, e As System.EventArgs) Handles NotifyIcon1.Click
MessageBox.Show("Notify clicked")
End Sub看看第一行。你有MouseEventArgs,它应该是System.EventArgs,你的句柄不应该是MouseClick,而是NotifyIcon1.Click。
发布于 2015-07-15 05:01:38
这样的解决方案如何:
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然后在您的表单中或任何位置:
' 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 Subhttps://stackoverflow.com/questions/31408475
复制相似问题