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(); } } } } }