1.1 --- a/Server/MainForm.cs Sun Jan 18 14:18:28 2015 +0100
1.2 +++ b/Server/MainForm.cs Sun Jan 18 18:11:32 2015 +0100
1.3 @@ -14,6 +14,7 @@
1.4 using System.Threading;
1.5 using System.Diagnostics;
1.6 using System.Deployment.Application;
1.7 +using System.Reflection;
1.8 //
1.9 using SharpDisplayClient;
1.10 using SharpDisplay;
1.11 @@ -57,9 +58,16 @@
1.12 //Function pointer for pixel Y coordinate intercept
1.13 CoordinateTranslationDelegate iScreenY;
1.14
1.15 - //
1.16 + /// <summary>
1.17 + /// Manage run when Windows startup option
1.18 + /// </summary>
1.19 private StartupManager iStartupManager;
1.20
1.21 + /// <summary>
1.22 + /// System tray icon.
1.23 + /// </summary>
1.24 + private NotifyIconAdv iNotifyIcon;
1.25 +
1.26 public MainForm()
1.27 {
1.28 iCurrentClientSessionId = "";
1.29 @@ -68,14 +76,26 @@
1.30 iDisplay = new Display();
1.31 iClients = new Dictionary<string, ClientData>();
1.32 iStartupManager = new StartupManager();
1.33 + iNotifyIcon = new NotifyIconAdv();
1.34
1.35 InitializeComponent();
1.36 UpdateStatus();
1.37 //We have a bug when drawing minimized and reusing our bitmap
1.38 iBmp = new System.Drawing.Bitmap(tableLayoutPanel.Width, tableLayoutPanel.Height, PixelFormat.Format32bppArgb);
1.39 iCreateBitmap = false;
1.40 +
1.41 + if (Properties.Settings.Default.StartMinimized)
1.42 + {
1.43 + WindowState = FormWindowState.Minimized;
1.44 + }
1.45 +
1.46 }
1.47
1.48 + /// <summary>
1.49 + ///
1.50 + /// </summary>
1.51 + /// <param name="sender"></param>
1.52 + /// <param name="e"></param>
1.53 private void MainForm_Load(object sender, EventArgs e)
1.54 {
1.55 if (ApplicationDeployment.IsNetworkDeployed)
1.56 @@ -94,10 +114,53 @@
1.57 OpenDisplayConnection();
1.58 }
1.59
1.60 - //
1.61 + //Check if "run on Windows startup" is enabled
1.62 checkBoxAutoStart.Checked=iStartupManager.Startup;
1.63 +
1.64 +
1.65 + //Setup notification icon
1.66 + iNotifyIcon.Icon = GetIcon("vfd.ico");
1.67 + iNotifyIcon.Text = "Sharp Display Manager";
1.68 + iNotifyIcon.Visible = true;
1.69 + iNotifyIcon.DoubleClick += delegate(object obj, EventArgs args)
1.70 + {
1.71 + SysTrayHideShow();
1.72 + };
1.73 +
1.74 + // To make sure start up with minimize to tray works
1.75 + if (WindowState == FormWindowState.Minimized && Properties.Settings.Default.MinimizeToTray)
1.76 + {
1.77 + Visible = false;
1.78 + }
1.79 }
1.80
1.81 + /// <summary>
1.82 + /// Access icons from embedded resources.
1.83 + /// </summary>
1.84 + /// <param name="name"></param>
1.85 + /// <returns></returns>
1.86 + public static Icon GetIcon(string name)
1.87 + {
1.88 + name = "SharpDisplayManager.Resources." + name;
1.89 +
1.90 + string[] names =
1.91 + Assembly.GetExecutingAssembly().GetManifestResourceNames();
1.92 + for (int i = 0; i < names.Length; i++)
1.93 + {
1.94 + if (names[i].Replace('\\', '.') == name)
1.95 + {
1.96 + using (Stream stream = Assembly.GetExecutingAssembly().
1.97 + GetManifestResourceStream(names[i]))
1.98 + {
1.99 + return new Icon(stream);
1.100 + }
1.101 + }
1.102 + }
1.103 +
1.104 + return null;
1.105 + }
1.106 +
1.107 +
1.108 /// <summary>
1.109 /// Set our current client.
1.110 /// This will take care of applying our client layout and set data fields.
1.111 @@ -520,6 +583,8 @@
1.112
1.113 CheckFontHeight();
1.114 checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup;
1.115 + checkBoxMinimizeToTray.Checked = Properties.Settings.Default.MinimizeToTray;
1.116 + checkBoxStartMinimized.Checked = Properties.Settings.Default.StartMinimized;
1.117 checkBoxReverseScreen.Checked = cds.ReverseScreen;
1.118 checkBoxInverseColors.Checked = cds.InverseColors;
1.119 comboBoxDisplayType.SelectedIndex = cds.DisplayType;
1.120 @@ -602,6 +667,27 @@
1.121 Properties.Settings.Default.Save();
1.122 }
1.123
1.124 + private void checkBoxMinimizeToTray_CheckedChanged(object sender, EventArgs e)
1.125 + {
1.126 + //Save our "Minimize to tray" setting
1.127 + Properties.Settings.Default.MinimizeToTray = checkBoxMinimizeToTray.Checked;
1.128 + Properties.Settings.Default.Save();
1.129 +
1.130 + }
1.131 +
1.132 + private void checkBoxStartMinimized_CheckedChanged(object sender, EventArgs e)
1.133 + {
1.134 + //Save our "Start minimized" setting
1.135 + Properties.Settings.Default.StartMinimized = checkBoxStartMinimized.Checked;
1.136 + Properties.Settings.Default.Save();
1.137 + }
1.138 +
1.139 + private void checkBoxAutoStart_CheckedChanged(object sender, EventArgs e)
1.140 + {
1.141 + iStartupManager.Startup = checkBoxAutoStart.Checked;
1.142 + }
1.143 +
1.144 +
1.145 private void checkBoxReverseScreen_CheckedChanged(object sender, EventArgs e)
1.146 {
1.147 //Save our reverse screen setting
1.148 @@ -1413,10 +1499,37 @@
1.149 }
1.150 }
1.151
1.152 - private void checkBoxAutoStart_CheckedChanged(object sender, EventArgs e)
1.153 +
1.154 + /// <summary>
1.155 + /// Used to
1.156 + /// </summary>
1.157 + private void SysTrayHideShow()
1.158 {
1.159 - iStartupManager.Startup = checkBoxAutoStart.Checked;
1.160 + Visible = !Visible;
1.161 + if (Visible)
1.162 + {
1.163 + Activate();
1.164 + WindowState = FormWindowState.Normal;
1.165 + }
1.166 }
1.167 +
1.168 + /// <summary>
1.169 + /// Use to handle minimize events.
1.170 + /// </summary>
1.171 + /// <param name="sender"></param>
1.172 + /// <param name="e"></param>
1.173 + private void MainForm_SizeChanged(object sender, EventArgs e)
1.174 + {
1.175 + if (WindowState == FormWindowState.Minimized && Properties.Settings.Default.MinimizeToTray)
1.176 + {
1.177 + if (Visible)
1.178 + {
1.179 + SysTrayHideShow();
1.180 + }
1.181 + }
1.182 +
1.183 + }
1.184 +
1.185 }
1.186
1.187 /// <summary>