Adding tray icon context menu.
authorsl
Sun, 18 Jan 2015 18:32:32 +0100
changeset 95a4a02cc952a0
parent 94 fe939a729030
child 96 f3322473db40
Adding tray icon context menu.
Server/MainForm.cs
Server/SharpDisplayManager.csproj
     1.1 --- a/Server/MainForm.cs	Sun Jan 18 18:11:32 2015 +0100
     1.2 +++ b/Server/MainForm.cs	Sun Jan 18 18:32:32 2015 +0100
     1.3 @@ -119,13 +119,7 @@
     1.4  
     1.5  
     1.6  			//Setup notification icon
     1.7 -			iNotifyIcon.Icon = GetIcon("vfd.ico");
     1.8 -			iNotifyIcon.Text = "Sharp Display Manager";
     1.9 -			iNotifyIcon.Visible = true;
    1.10 -			iNotifyIcon.DoubleClick += delegate(object obj, EventArgs args)
    1.11 -			{
    1.12 -				SysTrayHideShow();
    1.13 -			};
    1.14 +			SetupTrayIcon();
    1.15  
    1.16  			// To make sure start up with minimize to tray works
    1.17  			if (WindowState == FormWindowState.Minimized && Properties.Settings.Default.MinimizeToTray)
    1.18 @@ -135,6 +129,45 @@
    1.19          }
    1.20  
    1.21  		/// <summary>
    1.22 +		/// 
    1.23 +		/// </summary>
    1.24 +		private void SetupTrayIcon()
    1.25 +		{
    1.26 +			iNotifyIcon.Icon = GetIcon("vfd.ico");
    1.27 +			iNotifyIcon.Text = "Sharp Display Manager";
    1.28 +			iNotifyIcon.Visible = true;
    1.29 +
    1.30 +			//Double click toggles visibility - typically brings up the application
    1.31 +			iNotifyIcon.DoubleClick += delegate(object obj, EventArgs args)
    1.32 +			{
    1.33 +				SysTrayHideShow();
    1.34 +			};
    1.35 +
    1.36 +			//Adding a context menu, useful to be able to exit the application
    1.37 +			ContextMenu contextMenu = new ContextMenu();
    1.38 +			//Context menu item to toggle visibility
    1.39 +			MenuItem hideShowItem = new MenuItem("Hide/Show");
    1.40 +			hideShowItem.Click += delegate(object obj, EventArgs args)
    1.41 +			{
    1.42 +				SysTrayHideShow();
    1.43 +			};
    1.44 +			contextMenu.MenuItems.Add(hideShowItem);
    1.45 +
    1.46 +			//Context menu item separator
    1.47 +			contextMenu.MenuItems.Add(new MenuItem("-"));
    1.48 +
    1.49 +			//Context menu exit item
    1.50 +			MenuItem exitItem = new MenuItem("Exit");
    1.51 +			exitItem.Click += delegate(object obj, EventArgs args)
    1.52 +			{
    1.53 +				Application.Exit();
    1.54 +			};
    1.55 +			contextMenu.MenuItems.Add(exitItem);
    1.56 +
    1.57 +			iNotifyIcon.ContextMenu = contextMenu;
    1.58 +		}
    1.59 +
    1.60 +		/// <summary>
    1.61  		/// Access icons from embedded resources.
    1.62  		/// </summary>
    1.63  		/// <param name="name"></param>
     2.1 --- a/Server/SharpDisplayManager.csproj	Sun Jan 18 18:11:32 2015 +0100
     2.2 +++ b/Server/SharpDisplayManager.csproj	Sun Jan 18 18:32:32 2015 +0100
     2.3 @@ -31,7 +31,7 @@
     2.4      <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
     2.5      <WebPage>index.htm</WebPage>
     2.6      <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
     2.7 -    <ApplicationRevision>20</ApplicationRevision>
     2.8 +    <ApplicationRevision>22</ApplicationRevision>
     2.9      <ApplicationVersion>0.1.0.%2a</ApplicationVersion>
    2.10      <UseApplicationTrust>false</UseApplicationTrust>
    2.11      <CreateDesktopShortcut>true</CreateDesktopShortcut>