I have a form with CancelButton and AcceptButton (named btnCancel and btnOK). And I have some ComboBoxes as input fields.
ComboBoxes prevent my AcceptButton and CancelBu
While I have no idea about the main reason behind this behavior.
But in this situation obviously KeyDown
event triggers 2 times. (Set a breakpoint and you will see.)
Since you need to handle it in code, You can try this to neglect one of Enter keys:
bool handled = true;
private void comboBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
/*Prevent handling the Enter key twice*/
handled = !handled;
if(handled)
return;
//Rest of logic
//OkButton.PerformClick();
}
}