|
using System;
using System.Diagnostics;
using System.Windows.Forms;
using SystemTrayApp.Properties;
using System.Drawing;
namespace SystemTrayApp
{
/// <summary>
///
/// </summary>
class ContextMenus
{
/// <summary>
/// Is the About box displayed?
/// </summary>
bool isAboutLoaded = false;
/// <summary>
/// Creates this instance.
/// </summary>
/// <returns>ContextMenuStrip</returns>
public ContextMenuStrip Create()
{
// Add the default menu options.
ContextMenuStrip menu = new ContextMenuStrip();
ToolStripMenuItem item;
ToolStripSeparator sep;
// Windows Explorer.
item = new ToolStripMenuItem();
item.Text = "Explorer";
item.Click += new EventHandler(Explorer_Click);
item.Image = Resources.Explorer;
menu.Items.Add(item);
// About.
item = new ToolStripMenuItem();
item.Text = "About";
item.Click += new EventHandler(About_Click);
item.Image = Resources.About;
menu.Items.Add(item);
// Separator.
sep = new ToolStripSeparator();
menu.Items.Add(sep);
// Exit.
item = new ToolStripMenuItem();
item.Text = "Exit";
item.Click += new System.EventHandler(Exit_Click);
item.Image = Resources.Exit;
menu.Items.Add(item);
return menu;
}
/// <summary>
/// Handles the Click event of the Explorer control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
void Explorer_Click(object sender, EventArgs e)
{
Process.Start("explorer", null);
}
/// <summary>
/// Handles the Click event of the About control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
void About_Click(object sender, EventArgs e)
{
if (!isAboutLoaded)
{
isAboutLoaded = true;
new AboutBox().ShowDialog();
isAboutLoaded = false;
}
}
/// <summary>
/// Processes a menu item.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
void Exit_Click(object sender, EventArgs e)
{
// Quit without further ado.
Application.Exit();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.