vb.net 创建从系统托盘运行的程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18100322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 17:04:11  来源:igfitidea点击:

Create a program to run from the system tray

vb.netvisual-studio-2010

提问by Pavle Stojanovic

I would like to create a program to run from the bottom right system tray of Windows.

我想创建一个从 Windows 右下角系统托盘运行的程序。

But I don't know where to start from?

但我不知道从哪里开始?

Can someone tell \ show me where to look and examples or what commands to use \ research ?

有人可以告诉\告诉我在哪里查看和示例或使用什么命令\研究?

回答by jlvaquero

Add a NotifyIconto the main windows form. Use the Resizeevent in Formto control when to show the NotifyIconand hide the form:

将 a 添加NotifyIcon到主窗口窗体。使用Resize事件 inForm控制何时显示NotifyIcon和隐藏表单:

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Minimized Then
                NotifyIcon1.Visible = true
                Me.Hide()
                NotifyIcon1.BalloonTipText = "Hi from right system tray"
                NotifyIcon1.ShowBalloonTip(500)
        End If
    End Sub

Use the events in NotifyIcon to show the form again:

使用 NotifyIcon 中的事件再次显示表单:

Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
        Me.Show()
        Me.WindowState = FormWindowState.Normal
        NotifyIcon1.Visible = False
    End Sub

You can download a full example in AutoDNIEgoogle code project

您可以在AutoDNIE谷歌代码项目中下载完整示例

回答by Doberon

I review the answers I note that miss the icon.

我查看了我注意到错过图标的答案。

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
    If Me.WindowState = FormWindowState.Minimized Then
        NotifyIcon1.Visible = True
        NotifyIcon1.Icon = SystemIcons.Application
        NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
        NotifyIcon1.BalloonTipTitle = "Verificador corriendo"
        NotifyIcon1.BalloonTipText = "Verificador corriendo"
        NotifyIcon1.ShowBalloonTip(50000)
        'Me.Hide()
        ShowInTaskbar = False
    End If
End Sub

Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
    'Me.Show()
    ShowInTaskbar = True
    Me.WindowState = FormWindowState.Normal
    NotifyIcon1.Visible = False
End Sub

回答by Rob

You can also do:

你也可以这样做:

Sub ToggleHide()
    If Me.WindowState = FormWindowState.Normal Then
        Me.ShowInTaskbar = False
        Me.WindowState = FormWindowState.Minimized
    Else
        Me.ShowInTaskbar = True
        Me.WindowState = FormWindowState.Normal
    End If
End Sub