Monday, 2 June 2014

How to Minimize an Application to the Taskbar Tray in C#.Net | System Tray Application C#

6/02/2014 - By Pranav Singh 0

Displaying you application on icon is one of the most exciting part in the windows application. For this article i have used windows form and c#.Net.

Before moving  forward please check my some of the listbox articles Transfer Listbox Items to Another Listbox Using C#.Net and VB.Net | How to Move List Box Items to another List Box in C# in windows application.


So for this article first we will create a new windows application and after that we will add blank form in it.
After creating a blank form we will add a notify control from our toolbox.



Now we will set the icon from property window for NotifyIcon Control.




Now add the below code in your code form.

C#.Net
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace ProjectDemo_Windows
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        /// For form load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            notifyIcon1.BalloonTipTitle = "Notify Icon";
            notifyIcon1.BalloonTipText = "Notify Icon Test";
        }
        /// <summary>
        /// For minimizing the window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Resize(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                ShowInTaskbar = false;
                notifyIcon1.Visible = true;
                /*For setting display interval of bubble tool tip*/
                notifyIcon1.ShowBalloonTip(2000);
            }
        }
        /// <summary>
        /// for Rexize the window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ShowInTaskbar = true;
            notifyIcon1.Visible = false;
            WindowState = FormWindowState.Normal;
        }
    }
}

In above code first we are setting title and content for the bubble tool tip which will appear after minimizing the form.

        private void Form1_Load(object sender, EventArgs e)
        {
            notifyIcon1.BalloonTipTitle = "Notify Icon";
            notifyIcon1.BalloonTipText = "Notify Icon Test";
        }

Now will write code when user minimizes the form by using minimize button.

private void Form1_Resize(object sender, EventArgs e)
        {
            if (WindowState == FormWindowState.Minimized)
            {
                ShowInTaskbar = false;
                notifyIcon1.Visible = true;
                /*For setting display interval of bubble tool tip*/
                notifyIcon1.ShowBalloonTip(2000);
            }
        }

In above code we are checking what user is going to do if form minimize event is getting fired then the above piece of code will execute.


Here is the final piece of code which is used for reopening the for again when user click on icon.

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ShowInTaskbar = true;
            notifyIcon1.Visible = false;
            WindowState = FormWindowState.Normal;
        }

Now we have done. Now run the application.




Now click on minimize button. You will see your form in system tray


Now double click on system tray icon to re-open the form.

DOWNLOAD



About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top