Created
August 11, 2014 23:42
-
-
Save nramsbottom/01241537eb1267c1a2b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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