Winforms:关闭程序到系统托盘

时间:2011-10-01 20:05:28

标签: vb.net winforms

'This is the event that is fired as the application is closing, whether it
'be from a close button in the application or from the user
'clicking the X in the upper right hand corner
Private Sub Form1_FormClosing(sender as Object, e as FormClosingEventArgs)   Handles Form1.FormClosing
         'What we will do here is trap the closing of the application and send the application
         'to the system tray (or so it will appear, we will just make it invisible, re-showing
         'it will be up to you and your notify icon)

        'First minimize the form
         Me.WindowState = FormWindowState.Minimized

        'Now make it invisible (make it look like it went into the system tray)
        Me.Visible = False
End Sub

再次问好Stackoverflow!

我试图制作一个应用程序,当你按X时,程序被放入系统托盘。但我不知道我是如何做到这一点的,所以在谷歌搜索并找到了这段代码。只有VB2010(我使用的)不喜欢第四行。任何人都可以给我一个快速的教程,并在VB 2010中使这个工作?

顺便说一句,我很可能今晚只使用VB,只是为了制作一个应用程序。所以我不想考虑学习整个语言。

1 个答案:

答案 0 :(得分:1)

您好像在Dream.In.Code: Minimize To System Tray

找到了代码

您是否“继续”阅读其余信息?

您需要添加:

e.Cancel = True

到您的FormClosing事件,否则程序就会结束。此外,您还需要添加NotifyIcon组件和ContextMenuStrip。