I've deployed a project on client PC. Is it possible to add a shortcut key to invoke this program. How to make it minimized to the tray when it's triggered? (User can still open it by clicking the icon in the tray) Is it possible to do this on programming level?
migrated from stackoverflow.com Aug 23 '12 at 19:33
This question came from our site for professional and enthusiast programmers.
You can use a product like Auto Hotkeys which is free and good for defining hotkeys (and auto spell checking etc).
For system Tray, the usual way to do this is to not have the project as a forms project, but as a console project that calls a form. This way the form is not used until it is called from the system tray context menu - Look into NotifyIcon - Simple example Here. The other (less tidy) way is to have the main from hiden at the start, but if the form is not needed, it is a waste of respources really.
You cannot set a hotkey using C# code... Your application need to run if you want to set anything, and you want to trigger it to run using a shortkey... Ofcourse this can be set in t he settings of your application... rightclick your application, settings en find the item that lets you specify a shortkey to start the application.
To the tray icon question. You just need to hide your form, i'm assuming have build a forms application for this.
You can do this with the following code:
this code was taken from http://alanbondo.wordpress.com/2008/06/22/creating-a-system-tray-app-with-c/ which works like a charm!