开发者

Winforms: Closing a program to system tray

'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)
        开发者_如何学JAVAMe.Visible = False
End Sub

Hello again Stackoverflow!

Im trying to make an application that when you press X, the program gets put in system tray. But i have like no idea how i'm suppost to do that, so did a search on google and found this code. Only VB2010 (what i use) doesn't like the fourth line. Can anybody give me a quick tutorial on this, and make this work in VB 2010?

By the way, i will most likely use VB only tonight, just to make one application. So im not thinking of learing the whole language.


It looks like you found code over here Dream.In.Code: Minimize To System Tray

Did you "keep" reading the rest of the messages?

You need to add:

e.Cancel = True

to your FormClosing event or else the program just ends. Also, you need to add the NotifyIcon component and a ContextMenuStrip.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜