I have got some controls on the Panel and I am trying to delete them using "Delete" button. I handled KeyPress Event as mentioned in How to get Keypress event in Windows Panel control
Your issue is that the event MainForm_KeyUp does not even get fired on your key up, because you have focues another control. But you can fix that with KeyPreview.
A Form object has the property KeyPreview. According to the MSDN:
Gets or sets a value indicating whether the form will receive key events before the event is passed to the control that has focus.
So when you set:
this.KeyPreview = true;
You enable that your MainForm gets notified about those key events always. Even when any other Control is focused. So you enable that those key events will invoke MainForm_KeyUp().
Now set a breakpoint:
private void MainForm_KeyUp(object sender, KeyEventArgs e)
{
//set a breakpoint here, so you get confirmation, that the event will get fired
//on key up of the *delete* button
//...now do what you desire
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With