Windows Forms: Minimize application to system tray in C#

This post shows you How to minimize application to system tray in C# Windows Forms Application.

Creating a new form, then drag a NotifyIcon control from the Visual Studio toolbox into your form designer.

C# start application minimized to tray

Next, Click the arrow icon on NotifyIcon, then select an icon.

c# notifyicon

Adding a Load event handler to your form allows you to set title and content for the notifyicon.

private void frmSystemTray_Load(object sender, EventArgs e)
{
    notifyIcon1.BalloonTipText = "Application Minimized.";
    notifyIcon1.BalloonTipTitle = "FoxLearn";
}

Adding a Resize event handler to your form allows you to check the status of the window if it is minimized we will display the notification icon in the system tray.

private void frmSystemTray_Resize(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Minimized)
    {
        ShowInTaskbar = false;
        notifyIcon1.Visible = true;
        notifyIcon1.ShowBalloonTip(1000);
    }
}

C# system tray notification

Adding a MouseDoubleClick event handler to the NotifyIcon allows you to hide the NotifyIcon, then display your form.

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

C# run application in system tray

When you run and minimize apps you'll see a notification in the system tray.

c# run application in system tray

Through this c# example, i showed you how to create a system tray icon in a windows application using c#.

Related