/// <summary> /// Control.KeyDown Event handler. When a key is pressed down, remove key from the form. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">The <see cref="object"/> instance containing the event data.</param> private void Form1_KeyDown(object sender, KeyEventArgs e) { string _key = e.KeyCode.ToString(); Debug.WriteLine(_key); if (e.KeyCode == Keys.ShiftKey) { if (Convert.ToBoolean(GetAsyncKeyState(Keys.LShiftKey))) { Shift_L.Dispose(); } if (Convert.ToBoolean(GetAsyncKeyState(Keys.RShiftKey))) { if (Shift_R.Visible) { Shift_R.Dispose(); } } } else if (e.KeyCode == Keys.ControlKey) { if (Convert.ToBoolean(GetAsyncKeyState(Keys.LControlKey))) { Ctrl_L.Dispose(); } if (Convert.ToBoolean(GetAsyncKeyState(Keys.RControlKey))) { if (Ctrl_R.Visible) { Ctrl_R.Dispose(); } } } else if (e.KeyCode == Keys.Menu) { if (Convert.ToBoolean(GetAsyncKeyState(Keys.LMenu))) { Alt_L.Dispose(); } if (Convert.ToBoolean(GetAsyncKeyState(Keys.RMenu))) { if (Alt_R.Visible) { Alt_R.Dispose(); } } } else if (e.KeyCode == Keys.LWin || e.KeyCode == Keys.RWin) { Win.Dispose(); } else { Control[] _control = this.Controls.Find(_key, true); if (_control.Length > 0) { Control c = _control[0]; if (c.Visible) { c.Dispose(); } } } if ((tableLayoutPanel1.Controls.Count - HiddenKeys) == 1) { TestPass(); } }