# HG changeset patch # User sl # Date 1421602352 -3600 # Node ID a4a02cc952a0c557d9a601ff49d8df414c211126 # Parent fe939a729030c3b0dfd2da85c1edfa159cbb65ae Adding tray icon context menu. diff -r fe939a729030 -r a4a02cc952a0 Server/MainForm.cs --- a/Server/MainForm.cs Sun Jan 18 18:11:32 2015 +0100 +++ b/Server/MainForm.cs Sun Jan 18 18:32:32 2015 +0100 @@ -119,13 +119,7 @@ //Setup notification icon - iNotifyIcon.Icon = GetIcon("vfd.ico"); - iNotifyIcon.Text = "Sharp Display Manager"; - iNotifyIcon.Visible = true; - iNotifyIcon.DoubleClick += delegate(object obj, EventArgs args) - { - SysTrayHideShow(); - }; + SetupTrayIcon(); // To make sure start up with minimize to tray works if (WindowState == FormWindowState.Minimized && Properties.Settings.Default.MinimizeToTray) @@ -135,6 +129,45 @@ } /// + /// + /// + private void SetupTrayIcon() + { + iNotifyIcon.Icon = GetIcon("vfd.ico"); + iNotifyIcon.Text = "Sharp Display Manager"; + iNotifyIcon.Visible = true; + + //Double click toggles visibility - typically brings up the application + iNotifyIcon.DoubleClick += delegate(object obj, EventArgs args) + { + SysTrayHideShow(); + }; + + //Adding a context menu, useful to be able to exit the application + ContextMenu contextMenu = new ContextMenu(); + //Context menu item to toggle visibility + MenuItem hideShowItem = new MenuItem("Hide/Show"); + hideShowItem.Click += delegate(object obj, EventArgs args) + { + SysTrayHideShow(); + }; + contextMenu.MenuItems.Add(hideShowItem); + + //Context menu item separator + contextMenu.MenuItems.Add(new MenuItem("-")); + + //Context menu exit item + MenuItem exitItem = new MenuItem("Exit"); + exitItem.Click += delegate(object obj, EventArgs args) + { + Application.Exit(); + }; + contextMenu.MenuItems.Add(exitItem); + + iNotifyIcon.ContextMenu = contextMenu; + } + + /// /// Access icons from embedded resources. /// /// diff -r fe939a729030 -r a4a02cc952a0 Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Sun Jan 18 18:11:32 2015 +0100 +++ b/Server/SharpDisplayManager.csproj Sun Jan 18 18:32:32 2015 +0100 @@ -31,7 +31,7 @@ true index.htm false - 20 + 22 0.1.0.%2a false true