How to use a function for every C# WinForm instead of pasting .

Posted by nXqd on Stack Overflow See other posts from Stack Overflow or by nXqd
Published on 2010-04-29T05:20:37Z Indexed on 2010/04/29 5:27 UTC
Read the original article Hit count: 175

Filed under:
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 :)

© Stack Overflow or respective owner

Related posts about c#