Archive Browser
Download ApplicationContextExample.zip, last updated 26/08/2013 (55.70 KB)
Download- md5: 672e52b457e869f33e5ad810cdf69182
using System;
using System.Drawing;
using System.Windows.Forms;
using ApplicationContextExample.Properties;
using Cyotek;
namespace ApplicationContextExample
{
internal class CustomApplicationContext : TrayIconApplicationContext
{
#region Instance Fields
private AboutDialog _aboutDialog;
private SettingsDialog _settingsDialog;
private StatusWindow _statusWindow;
#endregion
#region Constructors
public CustomApplicationContext()
{
this.TrayIcon.Icon = Resources.SmallIcon;
this.ContextMenu.Items.Add("&Settings...", null, this.SettingsContextMenuClickHandler).Font = new Font(this.ContextMenu.Font, FontStyle.Bold);
this.ContextMenu.Items.Add("-");
this.ContextMenu.Items.Add("&About...", null, this.AboutContextMenuClickHandler);
this.ContextMenu.Items.Add("-");
this.ContextMenu.Items.Add("E&xit", null, this.ExitContextMenuClickHandler);
}
#endregion
#region Overridden Members
protected override void OnTrayIconClick(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (_statusWindow == null)
{
_statusWindow = new StatusWindow();
_statusWindow.Show();
_statusWindow.Activate();
}
else
this.HideStatusWindow();
}
base.OnTrayIconClick(e);
}
protected override void OnTrayIconDoubleClick(MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
this.ShowSettings();
base.OnTrayIconDoubleClick(e);
}
#endregion
#region Members
private void AboutContextMenuClickHandler(object sender, EventArgs eventArgs)
{
this.HideStatusWindow();
if (_aboutDialog == null)
{
using (_aboutDialog = new AboutDialog())
_aboutDialog.ShowDialog();
_aboutDialog = null;
}
else
_aboutDialog.Activate();
}
private void ExitContextMenuClickHandler(object sender, EventArgs eventArgs)
{
this.ExitThread();
}
private void HideStatusWindow()
{
if (_statusWindow != null)
{
_statusWindow.Dispose();
_statusWindow = null;
}
}
private void SettingsContextMenuClickHandler(object sender, EventArgs eventArgs)
{
this.ShowSettings();
}
private void ShowSettings()
{
this.HideStatusWindow();
if (_settingsDialog == null)
{
using (_settingsDialog = new SettingsDialog())
_settingsDialog.ShowDialog();
_settingsDialog = null;
}
else
_settingsDialog.Activate();
}
#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