0

我使用以下代码在 wpf 项目中创建了一个通知图标:

Dim ni = New System.Windows.Forms.NotifyIcon
Private Sub btnsystemtray_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles btnTaskbar.MouseUp
    ni.Visible = True
    ni.Icon = My.Resources.myicon
    Me.Hide()
End Sub

我能够使它工作,将窗口最小化到系统托盘。但是,我不知道如何为应该显示窗口的 notifyicon 创建一个单击事件。谢谢!

4

1 回答 1

1

WPF 没有对 NotifyIcon 的设计时支持,因此您必须在代码中进行。

Private WithEvents ni As New System.Windows.Forms.NotifyIcon

Private Sub ni_Click(sender As Object, e As System.EventArgs) Handles ni.Click
  Me.Show()
End Sub

请务必在退出时手动处理 NotifyIcon 以将其从系统托盘中删除:

Private Sub MainWindow_Closed(sender As Object, e As System.EventArgs) Handles Me.Closed
  ni.Dispose()
End Sub
于 2013-06-12T19:32:51.837 回答