protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
{
if (keyData == Keys.Escape) this.Close();
return base.ProcessCmdKey(ref msg, keyData);
}
}
I discovered this snippet to close windows form by esc. I really want to implement this to every windows form. I try to create a new abstract class which inherit from Form and another windows form will inherit from this one . But it doesn’t work this way .
abstract class AbsForm: Form {
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
{
if (keyData == Keys.Escape) this.Close();
return base.ProcessCmdKey(ref msg, keyData);
}
}
}
public partial class HoaDonBanSach : AbsForm
{
public HoaDonBanSach()
{
InitializeComponent();
}
Thanks for reading this 🙂
I would suggest not doing this in the Form but instead implement an IMessageFilter and add it using Application.AddMessageFilter. Something like the following: