dgzz
dgzz

Reputation: 3009

creating events for newly created windows form control (in wpf)

I created a notifyicon in a wpf project using this code:

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

I was able to make it work which minimizes the window to system tray. However, I don't know how to make a click event for the notifyicon which should show the window. Thanks!

Upvotes: 0

Views: 126

Answers (1)

Fuzhou Hu
Fuzhou Hu

Reputation: 538

WPF doesn't have design time support for NotifyIcon, so you'll have to do it in code.

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

Be sure to manually dispose the NotifyIcon on exit to remove it from the system tray:

Private Sub MainWindow_Closed(sender As Object, e As System.EventArgs) Handles Me.Closed
  ni.Dispose()
End Sub

Upvotes: 1

Related Questions