How to make a Windows Forms .NET application display as tray icon?

前端 未结 6 1994
孤城傲影
孤城傲影 2020-12-03 07:44

What needs to be done to have your .NET application show up in Window\'s system tray as icon?

And how do you handle mousebutton clicks on said icon?

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-03 08:09

    First, add a NotifyIcon control to the Form. Then wire up the Notify Icon to do what you want.

    If you want it to hide to tray on minimize, try this.

    Private Sub frmMain_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            Me.ShowInTaskbar = False
        Else
            Me.ShowInTaskbar = True
        End If
    End Sub
    
    Private Sub NotifyIcon1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick
        Me.WindowState = FormWindowState.Normal
    End Sub
    

    I'll occasionally use the Balloon Text in order to notify a user - that is done as such:

     Me.NotifyIcon1.ShowBalloonTip(3000, "This is a notification title!!", "This is notification text.", ToolTipIcon.Info)
    

提交回复
热议问题