2011-10-01 187 views
2
'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 

Hello again Stackoverflow!Winforms:关闭程序到系统托盘

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

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

+0

这不是关于Visual Studio,这是关于Winforms的。 Visual Studio也可以制作非窗口应用程序。请编辑您的问题和标签。 –

+0

我道歉,即时通讯新的。 – Thew

+0

不需要道歉:)我只是想指出Visual Studio和用来制作程序的API之间的区别。 –

回答

1

看起来你发现代码在这里Dream.In.Code: Minimize To System Tray

你“养”读消息的休息吗?

您需要添加:

e.Cancel = True 

FormClosing事件或其他程序刚刚结束。另外,您需要添加NotifyIcon组件和一个ContextMenuStrip。