472,133 Members | 1,158 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

How to run application from system tray

Hey
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,
Marc
Mar 24 '08 #1
3 1595
gpraghuram
1,275 Expert 1GB
I think this should be part of .NET forum

Raghuram
Mar 24 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
I ma moving this to the .NET forum.
Mar 24 '08 #3
Plater
7,872 Expert 4TB
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.

Similar topics

4 posts views Thread by Curious Coder | last post: by
1 post views Thread by Geraldine Hobley | last post: by
10 posts views Thread by Crouchie1998 | last post: by
11 posts views Thread by Jay | last post: by
4 posts views Thread by Octavius Khan | last post: by
1 post views Thread by =?Utf-8?B?RW5naW5lZXJpaw==?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.