using System; using System.Windows.Forms; namespace NotifyTest { static class Program { static NotifyIcon notifyIcon; /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); notifyIcon = new NotifyIcon { Visible = true, Icon = System.Drawing.SystemIcons.Information, BalloonTipTitle = "Testing", BalloonTipText = "This is only a test... " + Environment.NewLine + Environment.NewLine + "This message will close in 5 seconds." }; notifyIcon.BalloonTipClicked += NotifyIcon_BalloonTipClicked; notifyIcon.MouseClick += NotifyIcon_MouseClick; notifyIcon.ShowBalloonTip(5000); notifyIcon.BalloonTipClosed += NotifyIcon_BalloonTipClosed; ContextMenu contextMenu = new ContextMenu(); MenuItem menuItemClose = new MenuItem("&Close Tray"); menuItemClose.Click += MenuItemClose_Click; contextMenu.MenuItems.Add(menuItemClose); notifyIcon.ContextMenu = contextMenu; Application.Run(); } private static void NotifyIcon_BalloonTipClosed(object sender, EventArgs e) { notifyIcon.Visible = false; Application.Exit(); } private static void NotifyIcon_Click(object sender, EventArgs e) { notifyIcon.Visible = false; Application.Exit(); } private void NotifyIcon_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { notifyIcon.Visible = false; Application.Exit(); } else { // Show(); } } private static void NotifyIcon_BalloonTipClicked(object sender, EventArgs e) { notifyIcon.Visible = false; Application.Exit(); } } }