如何使Windows Forms .NET应用程序显示为任务栏图标?

时间:2020-03-06 14:59:22  来源:igfitidea点击:

要使.NET应用程序显示在Window的系统托盘中作为图标,需要做些什么?

以及如何处理所述图标上的鼠标按钮单击?

解决方案

我们可以从工具箱中将NotifyIcon组件添加到主窗体中。

它具有诸如MouseDoubleClick之类的事件,可用于处理各种事件。

编辑:如果我们希望图标属性正确显示在系统托盘中,则必须确保将Icon属性设置为有效的.ico文件。

关于在此处使用NotifyIcon类的不错的小教程:http://www.developer.com/net/csharp/article.php/3336751

将NotifyIcon组件添加到表单。并使用它的事件来处理鼠标单击。

首先,向表单添加一个NotifyIcon控件。然后连接"通知图标"以执行所需的操作。

如果我们希望将其隐藏在托盘上以将其最小化,请尝试此操作。

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

我偶尔会使用气球文本来通知用户已完成操作

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

这将显示并处理NotifyIcon的所有鼠标单击组合

此处更多内容:https://archive.codeplex.com/?p = notifyicon