private void replaceSelectedButton_Click(object sender, EventArgs e) { if (!updatingModes) { updatingModes = true; modeListEditor_Click(sender, e); //Create lists of the modes we need to add to the list, as well as all of the mode buttons currently in the list List <ModeControl> modeControlsToAdd = MainClientForm.instance.runModesLists.SelectedModeButtons; List <Button> buttons = OrderButtons(ModeButtons, ListModes.Modes); //For each selected button currently in the list, either replace it with one of the //modes we need to add to the list, or delete the button Button button; for (int ind = 0; ind < buttons.Count; ind++) { button = buttons[ind]; if (ModeButtons[button].Selected) { //If there are more modes to add, replace the current button's mode if (modeControlsToAdd.Count > 0) { ModeButtons[button] = new ModeControl(modeControlsToAdd[0]); button.Text = ModeButtons[button].Mode.ModeName; ColorBox(button); ModeButtons[button].ListPosition = ind; ListModes.Modes[ind] = ModeButtons[button]; modeControlsToAdd.RemoveAt(0); } else //Otherwise delete the button entirely { ListModes.Modes.Remove(ModeButtons[button]); DeleteDelayEditor(button); modesFlowPanel.Controls.Remove(button); ModeButtons.Remove(button); ListModes.UpdateListPositions(); } } } //If there are still modes left to add, do so now by creating new buttons for them foreach (ModeControl newMode in modeControlsToAdd) { ListModes.Modes.Add(new ModeControl(newMode)); ListModes.Modes.Last().ListPosition = ListModes.Modes.Count - 1; button = CreateButton(ListModes.Modes.Last()); modesFlowPanel.Controls.Add(button); CreateDelayEditor(newMode); } EnableAndDisableControls(); updatingModes = false; } }
public bool DeleteInputButton(Button button) { if (ModeButtons.Keys.Contains(button)) { ListModes.Modes.Remove(ModeButtons[button]); DeleteDelayEditor(button); modesFlowPanel.Controls.Remove(button); ModeButtons.Remove(button); ListModes.UpdateListPositions(); return(true); } return(false); }