using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing; using System.Windows; namespace sharpknife { public class TrayIcon : IDisposable { private Window window; private NotifyIcon notifyIcon; private static TrayIcon trayIcon; public static TrayIcon GetTrayIcon() { return trayIcon; } public TrayIcon(Window window) { this.window = window; notifyIcon = new System.Windows.Forms.NotifyIcon(); notifyIcon.Text = "SharpKnife"; try { notifyIcon.Icon = new Icon("Images/sharpknife.ico"); } catch (Exception ex) { System.Windows.MessageBox.Show("Error: " + ex.Message); } notifyIcon.Click += new EventHandler(NotifyIcon_Click); notifyIcon.Visible = true; trayIcon = this; } private void NotifyIcon_Click(object sender, EventArgs e) { window.Show(); } public void Message(string message) { if (notifyIcon != null) { notifyIcon.ShowBalloonTip(2000, "SharpKnife", message, ToolTipIcon.Info); } } public void Dispose() { notifyIcon.Dispose(); notifyIcon = null; } } }