Creating a System Tray Application with C#

This code snippet will show you how to create a minimal system tray application with C#.

using System;
using System.Drawing;
using System.Windows.Forms;

namespace MyTrayApp
    public class SysTrayApp : Form
        public static void Main()
            Application.Run(new SysTrayApp());

        private NotifyIcon  trayIcon;
        private ContextMenu trayMenu;

        public SysTrayApp()
            // Create a simple tray menu with only one item.
            trayMenu = new ContextMenu();
            trayMenu.MenuItems.Add("Exit", OnExit);

            // Create a tray icon. In this example we use a
            // standard system icon for simplicity, but you
            // can of course use your own custom icon too.
            trayIcon      = new NotifyIcon();
            trayIcon.Text = "MyTrayApp";
            trayIcon.Icon = new Icon(SystemIcons.Application, 40, 40);

            // Add menu to tray icon and show it.
            trayIcon.ContextMenu = trayMenu;
            trayIcon.Visible     = true;

        protected override void OnLoad(EventArgs e)
            Visible       = false; // Hide form window.
            ShowInTaskbar = false; // Remove from taskbar.


        private void OnExit(object sender, EventArgs e)

        protected override void Dispose(bool isDisposing)
            if (isDisposing)
                // Release the icon resource.


As always, you should add error handling where appropriate.

Tags: , ,

2 Responses to “Creating a System Tray Application with C#”

  1. ShaLi Says:

    Before I saw this article I had a problem hiding my main form, but this example worked perfectly.

    Thanks :)

  2. bd Says:

    thanks very short and straight to the point

Comments are closed.


Get every new post delivered to your Inbox.

%d bloggers like this: