Powered by Blogger.

Sunday, March 2, 2014

How to place C#.Net windows application to System Tray?




In this post we will discuss how we can place a windows application to System Tray. Also you can check out my previous posts on:

- Data files and Log files in sql server 2008

- Create a database by command in sql server 2008

- Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements

In this example we will see when user minimizes the form then the form will reside in the System Tray.

Follow below steps:
- Create a form (Right click on the Project, then Click on Add -> Add Windows Form...)

- Then drag and drop an NotifyIcon from the Toolbox. And then Right click on the NotifyIcon and click on Properties. There you can give a proper name, also you can upload an icon (.ico) file and then you can set the Text property which will appear when user put cursor on the NotifyIcon. It should be look like below:



- Now generate the event handler for the Resize evernt of the form and write the below code:

Here If the user click on Minimize it will hide the form.

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



0 comments

Post a Comment