如何使 Windows Forms .NET 应用程序显示为托盘图标? [英] How to make a Windows Forms .NET application display as tray icon?

查看:29
本文介绍了如何使 Windows Forms .NET 应用程序显示为托盘图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要做什么才能让您的 .NET 应用程序在 Window 的系统托盘中显示为图标?

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?

推荐答案

首先,添加一个 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)

这篇关于如何使 Windows Forms .NET 应用程序显示为托盘图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆