private void PrintHotKey(KeyEventArgs e, string text) { selectedTB.Text = text; if (e.KeyCode.ToString() != "ControlKey" && e.KeyCode.ToString() != "Menu" && e.KeyCode.ToString() != "ShiftKey") { selectedTB.Text += HotKeys.FindKeyValue(e.KeyValue.ToString()); e.SuppressKeyPress = true; KeyDown -= tb_KeyDown; } }
public EditHotKeys() { InitializeComponent(); ActiveControl = label1; KeyPreview = true; foreach (TextBox tb in panel1.Controls.OfType <TextBox>()) { tb.Click += (s, e) => { tbText = tb.Text; tb.Text = ""; selectedTB = tb; tb.KeyDown += tb_KeyDown; }; tb.LostFocus += (s, e) => { int qRepeat = 0; for (int i = 0; i < 4; i++) { if (tb.Text == panel1.Controls.OfType <TextBox>().ToArray()[i].Text) { qRepeat++; } } if (tb.Text == "Ctrl+" || tb.Text == "Alt+" || tb.Text == "Shift+" || tb.Text == "" || qRepeat >= 2) { tb.Text = tbText; } }; } TextBox[] tbs = panel1.Controls.OfType <TextBox>().ToArray(); for (int i = 0; i < 4; i++) { tbs[i].Text = $"{Program.modifiers[i]}+{HotKeys.FindKeyValue(Program.keys[i].ToString())}"; } }