Skip to content

Instantly share code, notes, and snippets.

@nramsbottom
Created August 11, 2014 23:42
Show Gist options
  • Select an option

  • Save nramsbottom/01241537eb1267c1a2b6 to your computer and use it in GitHub Desktop.

Select an option

Save nramsbottom/01241537eb1267c1a2b6 to your computer and use it in GitHub Desktop.
using System;
using System.Drawing;
using System.Windows.Forms;
// based on http://alanbondo.wordpress.com/2008/06/22/creating-a-system-tray-app-with-c/
namespace MyTrayApp
{
public partial class TrayApp : Form
{
[STAThread]
public static void Main()
{
Application.Run(new TrayApp());
}
private NotifyIcon trayIcon;
private ContextMenu trayMenu;
private const string ApplicationTitle = "MyTrayApp";
public TrayApp()
{
trayMenu = new ContextMenu();
trayMenu.MenuItems.Add("Exit", OnExit);
trayIcon = new NotifyIcon();
trayIcon.Text = ApplicationTitle;
trayIcon.Icon = new Icon(SystemIcons.Application, 40, 40);
trayIcon.ContextMenu = trayMenu;
trayIcon.Visible = true;
}
private void OnExit(object sender, EventArgs e)
{
Application.Exit();
}
protected override void OnLoad(EventArgs e)
{
Visible = false;
ShowInTaskbar = false;
base.OnLoad(e);
}
protected override void Dispose(bool disposing)
{
if (disposing)
trayIcon.Dispose();
base.Dispose(disposing);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment