WPF学习笔记-如何按ESC关闭窗口

如何按ESC关闭窗口?

在InitializeComponent();下面增加KeyDown事件,如:

     public ModifyPrice()
        {
            InitializeComponent();
            this.KeyDown += ModifyPrice_KeyDown;
        }

        private void ModifyPrice_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)//Esc键  
            {
                this.Close();
            }
        }

 

posted @ 2016-12-14 11:35  在路上的愚人  阅读(4658)  评论(0)    收藏  举报