0

I'd like to create a C# app that will only have a custom tray icon visible, nothing else. No main form, no tray icon menus, just the icon. What's the easiest way to do so?

I guess I should start out with a console application, since I don't need any forms. So far I only found complicated examples of how to hide the main form in a WinForms app, with a lot of other unnecessary stuff.

user1306322
  • 8,561
  • 18
  • 61
  • 122
  • Did you read this? http://stackoverflow.com/questions/995195/how-can-i-make-a-net-winforms-application-that-only-runs-in-the-system-tray – Matthias Oct 27 '13 at 20:47

1 Answers1

1

you can create an app context:

static class Program
    {       
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new TrayApplicationContext());
        }
    }

    public class TrayApplicationContext : ApplicationContext
    {
        private readonly NotifyIcon _trayIcon;
        public TrayApplicationContext()
        {
            _trayIcon = new NotifyIcon
                            {
                                //it is very important to set an icon, otherwise  you won't see your tray Icon.
                                Icon = Resources.AppIcon,                                
                                Visible = true
                            };
        }        
    }
Vladimir Gondarev
  • 1,243
  • 7
  • 14