private void SetButtonStates() { // Which buttons should be enabled: // Map button (aka UnMap, aka Set (for capture)) MapButton.Enabled = (capturingFromKey && !map.IsEmpty()) || mapped || (capturingFromKey && map.IsValid()) || (selectingFromKeyFromLists && KeysByGroupListbox.SelectedIndex >= 0) || (capturingToKey && map.IsValid()) || (!disabled && !capturingToKey && KeysByGroupListbox.SelectedIndex >= 0); // Capture buttons should only be enabled when form is not in mapped mode and not disabled // and not capturing.. CaptureAndCancelButton.Enabled = (!mapped && !disabled && !capturingFromKey && !selectingFromKeyFromLists); // Disabled button enabled when not mapped and not capturing. DisableButton.Enabled = (!mapped && !capturingToKey && !capturingFromKey && !selectingFromKeyFromLists); }
public AddEditMapping(KeyMapping map, bool useCapture) { InitializeComponent(); // There are four startup states for this form. // 1) Choose a From key by capturing it // 2) Choose a mapping for a specific From key // 3) Display a given mapping From and To. Includes disabled. // 4) Select a From key from the lists // Map is a struct so it can't be null. if (map.IsEmpty()) { if (useCapture) { // We are capturing the 'from' key. capturingFromKey = true; } else { selectingFromKeyFromLists = true; } } else { mapped = (map.To.Scancode > 0); disabled = (map.To.Scancode == 0); } newMapping = !map.IsValid(); this.map = map; // Default has the KeyLists panel in the frame. if (mapped | disabled) { SwopPanelPositions(KeyListsPanel, MappingPanel); } else if (capturingFromKey) { SwopPanelPositions(EmptyPanel, KeyListsPanel); } if (selectingFromKeyFromLists) { // Need to move the lists to the left where the box while remembering where it was savedPanelLocation = KeyListsPanel.Location; KeyListsPanel.Left = FromKeyPictureBox.Left; keyThreshold = -1; // Show all keys as possible map-ees } else { keyThreshold = 1; } SetListOptionsComboIndex(); PopulateKeyLists(); // Add event handlers now values have been assigned GroupsListbox.SelectedIndexChanged += GroupsListboxSelectedIndexChanged; KeysByGroupListbox.SelectedIndexChanged += KeysByGroupListboxSelectedIndexChanged; ListOptionsCombo.SelectedIndexChanged += ListOptionsComboSelectedIndexChanged; KeysByGroupListbox.DoubleClick += KeysByGroupListboxDoubleClick; SetupForm(); }