By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,714 Members | 1,345 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,714 IT Pros & Developers. It's quick & easy.

How to run application from system tray

P: 1
I'm pretty new to C# (started few hours ago) but i learn extremly fast, i have previous knowledge of php, javascript and flash.

I have made my first simple application the way i want it, however i'm having trouble with the system tray icon, i can show/hide the main window using the icon with a context menu etc.

However what i would like to do it to make the icon go to the system tray when i press the red cross in the top right corner rather than completly closing the application, and if someone wishes to close the application they right click the system tray icon and press exit (which i have already setup)

I asked a friend/coworker for some advice but he was busy, he did however say it had something to do with do with catching the SW_QUERYCLOSE event somewhere, but i've had no luck searching for that.

Any help is apreciated and thanks in advance for your time,
Mar 24 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 1,275
I think this should be part of .NET forum

Mar 24 '08 #2

Expert Mod 5K+
P: 9,197
I ma moving this to the .NET forum.
Mar 24 '08 #3

Expert 5K+
P: 7,872
Well there'a couple of different ways to do this.

Approach One:
You make an empty form and add the sys icon (NotifyIcon) to THAT form. Then set THAT form as the main start up form.
The only job of this form is to be invisible (visible=false) and to launch (keep a reference to) the form you actually want to show/hide. The functionality of the systray icon is changed to show/hide the form you just launched (instead of like this.visible=false, it would be myActualForm.Visible=false, etc)

Approach Two:
On the form you show/hide, you would attach an event handler to the Closing event for the form. There you would take action depending on what the type is (you would want to make sure the OS can close the program, only want to deal with the user tries to close).
You would also want to implent some logic (a simple boolean value perhaps?) to make sure your menu-click item is allowed to close the application as well.
Mar 24 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.