using System; using System.Diagnostics; using System.Windows.Forms; using SystemTrayApp.Properties; using System.Drawing; using Microsoft.Win32; namespace SystemTrayApp { /// /// /// class ContextMenus { /// /// Is the About box displayed? /// bool isAboutLoaded = false; /// /// Creates this instance. /// /// ContextMenuStrip public ContextMenuStrip Create() { // Add the default menu options. ContextMenuStrip menu = new ContextMenuStrip(); ToolStripMenuItem item; ToolStripSeparator sep; String[] values = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\HIS\\SystemTrayApp").GetSubKeyNames(); foreach (String value in values) Console.WriteLine(value); // Windows Explorer. item = new ToolStripMenuItem(); item.Text = "Network Information"; item.Click += new EventHandler(Network_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; } /// /// Handles the Click event of the Explorer control. /// /// The source of the event. /// The instance containing the event data. void Network_Click(object sender, EventArgs e) { // Process.Start("explorer", null); } /// /// Handles the Click event of the About control. /// /// The source of the event. /// The instance containing the event data. void About_Click(object sender, EventArgs e) { if (!isAboutLoaded) { isAboutLoaded = true; new AboutBox().ShowDialog(); isAboutLoaded = false; } } /// /// Processes a menu item. /// /// The sender. /// The instance containing the event data. void Exit_Click(object sender, EventArgs e) { // Quit without further ado. Application.Exit(); } } }