How to place your C# application in the System Tray

Hello people! It’s been an era since my last post, I’ve been busy and.. must confess, a little bit lazy to post here. But (again) I will try to keep this blog alive, since I’m dealing with different kind of problems every single day, I have a lot to contribute.

systray

It was no different today, I had to deal with a simple thing, how to place my application in the System Tray, simple, huh? But I had never done it before, so I’m going to do it in 4 quick steps. There’s no mistake.

1 – Assuming you have your application open already, add the component called notifyIcon, and name it the way you prefer.

notify

2 – First of all, we should set a image icon for our application, if you do not have it yet. Otherwise, it won’t appear in the SysTray.

3 – There’s only one single line you must add to place your application in the SysTray, and it’s the method called Hide().

private void Form1_Resize(object sender, EventArgs e)
{
    if (FormWindowState.Minimized == WindowState)
    {
        Hide();
    }
}

PS. Remember you can put it where it applies to you, I just chose when the application is being minimized because I think it makes more sense.

Alright, until now you have almost everything done, we should not forget about how to open up our application again, once it’s in the SysTray.

4 – Now click on your notifyIcon and take a look at its properties

notify2

Pretty intuitive, huh? I prefer to take the double click method and put my code like this:

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
    Show();
    WindowState = FormWindowState.Normal;
}

That’s it! You can also try different methods and properties, there’re only a few. You can download my test application here.

Hope you guys enjoy this post, it’s a simple one but useful sometimes.

Feel free to comment using the area below! Alegre

net1

Advertisements

2 comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s