private void hotkeyCheckbox_Click(object sender, EventArgs e) { // Get the checkbox that was clicked CheckBox cb = (CheckBox)sender; // Get the hotkey to adjust and the text box to query HotkeyController.HotKeyId hkid; TextBox tb = null; hkid = (HotkeyController.HotKeyId)cb.Tag; if (textboxDictionary.TryGetValue(hkid, out tb) == false) { // If we can't get the text box give up return; } // Unregister the hotkey if the box is unticked if (cb.Checked == false) { bool result = hkc.UnregisterHotKey(parentWindow, hkid); if (result == false) { MessageBox.Show(this, "Failed to unregister hotkey" , "Warning" , MessageBoxButtons.OK , MessageBoxIcon.Warning); } tb.Text = hkc.getHotKeyFromId(hkid); hkc.refreshHotkeys(); } else { if (tb.Text.Length != 1) { MessageBox.Show(this, "Hotkey must be specified" , "Warning" , MessageBoxButtons.OK , MessageBoxIcon.Warning); tb.Text = hkc.getHotKeyFromId(hkid); cb.Checked = false; } else { char newHotkey = tb.Text.ToCharArray(0, 1)[0]; if (hkc.isHotkeyAvailable(newHotkey) == false) { string warningMessage = "Hotkey may not be duplicated"; if (hkc.getModifier().ProtectedKeys.Length > 0) { warningMessage = warningMessage + " or one of the system keys: " + hkc.getModifier().ProtectedKeysDescription; } MessageBox.Show(this, warningMessage , "Warning" , MessageBoxButtons.OK , MessageBoxIcon.Warning); tb.Text = hkc.getHotKeyFromId(hkid); cb.Checked = false; } else { bool result = hkc.RegisterHotkey(parentWindow, newHotkey, hkid); if (result == false) { MessageBox.Show(this, "Failed to register hotkey" , "Warning" , MessageBoxButtons.OK , MessageBoxIcon.Warning); tb.Text = hkc.getHotKeyFromId(hkid); cb.Checked = false; } else { tb.Text = hkc.getHotKeyFromId(hkid); // Try to enable any associated combox box ComboBox cmb = null; comboDictionary.TryGetValue(hkid, out cmb); if (cb != null) { cb.Enabled = true; } hkc.refreshHotkeys(); } } } } }
private void LoadLayout() { optionsDialog = new Options(this); aboutDialog = new AboutBox(); sessionEditor = new SessionEditorForm(); hotKeyChooser = new HotkeyChooser(this); synchronizeForm = new SynchronizeForm(); // Attempt to override the system and taskbar tray icons string iconFile = Path.GetDirectoryName(Application.ExecutablePath) + "\\psm.ico"; if (File.Exists(iconFile)) { try { Icon psmIcon = new Icon(iconFile); systrayIcon.Icon = psmIcon; this.Icon = psmIcon; } catch (Exception) { // Do nothing } } if (Properties.Settings.Default.CloseToTray) { systrayIcon.Visible = true; } // Restore the size of the application this.ClientSize = Properties.Settings.Default.WindowSize; // Restore the location of the application Point savedLocation = Properties.Settings.Default.Location; // Get the screen that will display the point Screen display = Screen.FromPoint(savedLocation); // Check that the selected display contains the point // if not - restore the application in the top left hand corner if (display != null && display.Bounds.Contains(savedLocation)) { this.DesktopLocation = Properties.Settings.Default.Location; } else { this.DesktopLocation = new Point(0, 0); } // Reset the display to either the tree or the list displayTreeToolStripMenuItem.Checked = Properties.Settings.Default.DisplayTree; // Register the new session hotkey if enabled if (Properties.Settings.Default.HotkeyNewEnabled) { hkc.RegisterHotkey(this, HotkeyController.HotKeyId.HKID_NEW); } // Register the minimize hotkey if enabled if (Properties.Settings.Default.HotkeyMinimizeEnabled) { hkc.RegisterHotkey(this, HotkeyController.HotKeyId.HKID_MINIMIZE); } // Invalidate the session list to force a refresh of all forms sc.invalidateSessionList(this, true); // Expand the tree if requested on startup if (Properties.Settings.Default.ExpandTreeOnStartup) { sessionTreeControl.expandFullTree(); } // Setup the display setDisplay(); }