Archive Browser
Download AzureContainerEcho.zip version 1.0.0.0, last updated 08/09/2013 (341.35 KB)
Download- md5: 08cb1fda4e8e679d8fec0608417e3910
using System;
using System.Diagnostics;
using System.Windows.Forms;
// ReSharper disable CheckNamespace
namespace Cyotek // ReSharper restore CheckNamespace
{
public abstract class TrayIconApplicationContext : ApplicationContext
{
#region Instance Fields
private readonly ContextMenuStrip _contextMenu;
private readonly NotifyIcon _notifyIcon;
#endregion
#region Constructors
protected TrayIconApplicationContext()
{
_contextMenu = new ContextMenuStrip();
Application.ApplicationExit += this.ApplicationExitHandler;
_notifyIcon = new NotifyIcon
{
ContextMenuStrip = _contextMenu,
Text = Application.ProductName,
Visible = true
};
this.TrayIcon.MouseDoubleClick += this.TrayIconDoubleClickHandler;
this.TrayIcon.MouseClick += this.TrayIconClickHandler;
}
#endregion
#region Properties
protected ContextMenuStrip ContextMenu
{
get { return _contextMenu; }
}
protected NotifyIcon TrayIcon
{
get { return _notifyIcon; }
}
#endregion
#region Members
protected virtual void OnApplicationExit(EventArgs e)
{
if (_contextMenu != null)
_contextMenu.Dispose();
if (_notifyIcon != null)
{
_notifyIcon.Visible = false;
_notifyIcon.Dispose();
}
}
protected virtual void OnTrayIconClick(MouseEventArgs e)
{ }
protected virtual void OnTrayIconDoubleClick(MouseEventArgs e)
{ }
#endregion
#region Event Handlers
private void ApplicationExitHandler(object sender, EventArgs e)
{
this.OnApplicationExit(e);
}
private void TrayIconClickHandler(object sender, MouseEventArgs e)
{
Debug.Print("Icon click with {0} button", e.Button);
this.OnTrayIconClick(e);
}
private void TrayIconDoubleClickHandler(object sender, MouseEventArgs e)
{
Debug.Print("Icon double click with {0} button", e.Button);
this.OnTrayIconDoubleClick(e);
}
#endregion
}
}
Donate
This software may be used free of charge, but as with all free software there are costs involved to develop and maintain.
If this site or its services have saved you time, please consider a donation to help with running costs and timely updates.
Donate