如何使Windows窗体.NET应用程序显示为托盘图标?窗体、托盘、应用程序、图标

2023-09-02 10:31:04 作者:翩翩喜欢伱

需要做什么让你的.NET应用程序显示在窗口的系统托盘中的图标?

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

和你如何处理mousebutton点击所述图标?

And how do you handle mousebutton clicks on said icon?

推荐答案

首先,添加一个NotifyIcon控件到窗体。随后连线了通知图标做你想做的。

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)