[C#] Your program in System Tray (as icon)

cyberbrute

Registered Member
Joined
Jul 29, 2013
Messages
72
Reaction score
50
Hello guys,
I am new to this community and this is my first tutorial regarding .NET C#, Please ignore my mistakes if I am doing something wrong.


So here we go, I am sharing the way to "Show your Program in System Tray" , some of us surely know this but still this can help someone!
So firstly we are using a built in control of Visual Studio C# for Windows Form named "NotifyIcon".
Simply drag and drop it on your form.

Then go to its properties and change the icon (as per your needs, of course)!
(you can either download your desired icon from Google or can make your own in Photoshop or whatever software you are good in)

Ok not time for some coding, we are going to create "Resize" event of current Form!
then add these lines to event:

Code:
[COLOR=#faebd7][FONT=inherit]if ([/FONT]WindowState [FONT=inherit]==[/FONT] FormWindowState.[FONT=inherit]Minimized)[/FONT]
    [FONT=inherit]{[/FONT]        
[FONT=inherit]this[/FONT].[FONT=inherit]Hide()[/FONT];
[FONT=inherit]this[/FONT].[FONT=inherit]ShowInTaskbar[/FONT] [FONT=inherit]=[/FONT] false;
[FONT=inherit]}[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
[/FONT][/COLOR]

Whenever you will minimize your Form, it will go to System Tray.

Ok cool till now, so now you need to open program again, for this you can create another event of NotifyIcon named "DoubleClick" or "Click"
(choose event name as per your needs)

then add this following code into that even you created:

Code:
[COLOR=#faebd7][FONT=inherit]this[/FONT].[FONT=inherit]Show()[/FONT];
[FONT=inherit]this[/FONT].[FONT=inherit]WindowState[/FONT] [FONT=inherit]=[/FONT] FormWindowState.[FONT=inherit]Normal[/FONT];
[FONT=inherit]this[/FONT].[FONT=inherit]ShowInTaskbar[/FONT] [FONT=inherit]=[/FONT] true;[/COLOR]

and that's it, you have successfully added the feature to your application.
Hopefully someone will find this little tutorial helpful.

Thank you for reading my post, Please leave a comment. :)

Regards,
M.Waseem
 
one more thing is to dispose notifywindow when form closes..
 
Back
Top