Solution 1 : You need to set KeyPreview
Property of the Form to true
.
Try This:
this.KeyPreview = true;
Solution 2: But i would suggest you to override the ProcessCmdKey()
method as below
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
if (keyData == Keys.Y) {
btnYes.PerformClick();
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}