/// <summary> /// Updates the location of the form relevant to the selected display /// </summary> /// <param name="collapse">Display form in a collapsed/shrunk state</param> private void RefreshSwitchUI(bool collapse) { //Only set if form state changing if (iscollapsed != collapse) { //Set required size for form and show/hide panels with relevant controls if (!collapse) { this.Size = new Size(370, 95); pnlMin.Hide(); pnlMain.Show(); this.ControlBox = true; } else { this.Size = new Size(136, 95); pnlMain.Hide(); pnlMin.Show(); this.ControlBox = false; } } //Test if form is to be collapsed, and set the appropriate position for the form if (!collapse) { int[] windowpos = VNC_Screen.PositionForDisplay(false, RegistryManagement.GetRegistryValue("DisplayDevice")); this.Left = windowpos[0]; this.Top = windowpos[1]; } else { int[] windowpos = VNC_Screen.PositionForDisplay(true, RegistryManagement.GetRegistryValue("DisplayDevice")); this.Left = windowpos[0]; this.Top = windowpos[1]; } iscollapsed = collapse; }
/// <summary> /// Event fired when tmrCheckPrimaryScreen elapses - used to ensure we have recorded the correct primary display /// </summary> private void tmrCheckPrimaryScreen_Tick(object sender, EventArgs e) { if (RegistryManagement.GetRegistryValue("PrimaryMonitor") != VNC_Screen.GetPrimaryScreen().DeviceName) { RegistryManagement.SetRegistryValue("PrimaryMonitor", VNC_Screen.GetPrimaryScreen().DeviceName); } }
/// <summary> /// Event fired when tmrShowSwitchUI elapses - used to force frmSwitchUI to show if invoked via an appropriate command /// </summary> private void tmrShowSwitchUI_Tick(object sender, EventArgs e) { bool showuinow = false; if (RegistryManagement.GetRegistryValue("ShowUINow") != "") { showuinow = Convert.ToBoolean(RegistryManagement.GetRegistryValue("ShowUINow")); } if (showuinow) { RegistryManagement.SetRegistryValue("ShowUINow", "false"); ShowSwitchUI(true); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; string[] envargs = Environment.GetCommandLineArgs(); //Run custom actions if command line switches are present if (envargs.Length > 1) { for (int index = 1; index < envargs.Length; index++) { envargs[index] = envargs[index].TrimStart('-'); switch (envargs[index]) { //If application already running, force the UI to appear (this is used in Desktop shortcut) case "showui": if (AlreadyRunning()) { Application.Run(new frmTray(true)); } else { RegistryManagement.SetRegistryValue("ShowUINow", "true"); } break; //Start application with main UI not visible, used for logon event case "startup": Application.Run(new frmTray(false)); break; default: break; } } } else { //If already running, show UI, else exit program if (AlreadyRunning()) { Application.Run(new frmTray(true)); } } }
/// <summary> /// Event for our Registry polling Timer /// </summary> private void tmrCheckReg_Tick(object sender, EventArgs e) { //Don't fire if user is currently selecting a display if (!cmbDisplaySelector.DroppedDown) { //Only fire if the last session state indicates a user is currently logged in if (RegistryManagement.GetRegistryValue("SessionChange") == "SessionLogon" || RegistryManagement.GetRegistryValue("SessionChange") == "SessionUnlock") { //Check if the selected value is different to the set value if (cmbDisplaySelector.SelectedValue.ToString() != RegistryManagement.GetRegistryValue("DisplayDevice")) { //Set the combobox value to match the displayed screen from Registry if (RegistryManagement.GetRegistryValue("DisplayDevice") != "") { cmbDisplaySelector.SelectedIndex = VNC_Screen.EnumerateScreens().FindIndex(x => x.DeviceName == RegistryManagement.GetRegistryValue("DisplayDevice")); } else { cmbDisplaySelector.SelectedIndex = 0; } } } } }
/// <summary> /// When the combobox value is changed, set the Registry value using the selected value, and update position of form /// </summary> private void cmbDisplaySelector_SelectedIndexChanged(object sender, EventArgs e) { RegistryManagement.SetRegistryValue("DisplayDevice", cmbDisplaySelector.SelectedValue.ToString()); RefreshSwitchUI(false); }
/// <summary> /// COnstructor for the formo /// </summary> /// <param name="_allowclose">Is the form allowed to be closed (e.g. shown when VNC session not in progress)</param> public frmSwitchUI(bool _allowclose) { InitializeComponent(); allowclose = _allowclose; //Set datasource for combobox to a list of currently connected screens cmbDisplaySelector.DataSource = VNC_Screen.EnumerateScreens(); //Set combobox selection to match the current screen displayed from Registry value cmbDisplaySelector.SelectedIndex = VNC_Screen.EnumerateScreens().FindIndex(x => x.DeviceName == RegistryManagement.GetRegistryValue("DisplayDevice")); //Display full form RefreshSwitchUI(false); //Attach event handler for combobox cmbDisplaySelector.SelectedIndexChanged += new EventHandler(cmbDisplaySelector_SelectedIndexChanged); }