/// <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);
        }
 /// <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>
 /// Returns the VNC_Screen for the Primary display
 /// </summary>
 /// <returns>The matching VNC_Screen object</returns>
 public static VNC_Screen GetPrimaryScreen()
 {
     return(VNC_Screen.EnumerateScreens().Find(x => x.Primary == true));
 }