private void RightToonKeyPicker_KeyChosen(KeyPicker keyChooser, Keys keyChosen) { int rowNum = tableLayoutPanel1.GetRow(keyChooser); keyMappings[rowNum - 1].RightToonKey = keyChosen; KeyMappingsChanged?.Invoke(this, EventArgs.Empty); }
int addRow(KeyMapping keyMapping) { Point scrollPosition = this.AutoScrollPosition; Control label; if (keyMapping.ReadOnly) { label = new Label() { Text = keyMapping.Title.TrimEnd(':') + ":", Dock = DockStyle.Fill, AutoSize = true, TextAlign = ContentAlignment.MiddleLeft }; } else { TextBox textbox = new TextBox() { Text = keyMapping.Title.TrimEnd(':') + ":", Dock = DockStyle.Fill }; textbox.TextChanged += BindingTitle_TextChanged; textbox.Focus(); textbox.SelectAll(); label = textbox; } KeyPicker bindingKeyPicker = new KeyPicker() { Dock = DockStyle.Top, ChosenKey = keyMapping.Key }, leftToonKeyPicker = new KeyPicker() { Dock = DockStyle.Top, ChosenKey = keyMapping.LeftToonKey }, rightToonKeyPicker = new KeyPicker() { Dock = DockStyle.Top, ChosenKey = keyMapping.RightToonKey }; Button removeBtn = new Button() { Text = "Remove", AutoSize = true, Enabled = !keyMapping.ReadOnly }; bindingKeyPicker.KeyChosen += KeyChooser_KeyChosen; removeBtn.Click += RemoveBtn_Click; leftToonKeyPicker.KeyChosen += LeftToonKeyPicker_KeyChosen; rightToonKeyPicker.KeyChosen += RightToonKeyPicker_KeyChosen; tableLayoutPanel1.SuspendLayout(); tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize)); tableLayoutPanel1.RowCount++; int rowNum = tableLayoutPanel1.RowCount - 1; tableLayoutPanel1.Controls.Add(label, 0, rowNum); tableLayoutPanel1.Controls.Add(bindingKeyPicker, 1, rowNum); tableLayoutPanel1.Controls.Add(leftToonKeyPicker, 2, rowNum); tableLayoutPanel1.Controls.Add(rightToonKeyPicker, 3, rowNum); tableLayoutPanel1.Controls.Add(removeBtn, 4, rowNum); tableLayoutPanel1.ResumeLayout(); this.AutoScrollPosition = new Point(Math.Abs(scrollPosition.X), Math.Abs(scrollPosition.Y)); return(rowNum); }