如何使退出键分配给退出按钮? [英] How to make Escape key assigned to Exit button?

查看:72
本文介绍了如何使退出键分配给退出按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Microsoft Visual Studio 2010

I have the Microsoft visual studio 2010

我在编写代码方面遇到麻烦,因此当我按ESC时退出

Im having trouble on how to write the code so that when i press the ESC it exits

推荐答案


Citrus _,


Hi Citrus_,

根据您的描述,我认为您想按ESC键,然后WPF应用程序退出.

From your description, I think you want to press the ESC and the WPF application exits.

您可以尝试以下方式.

   public MainWindow()
        {
            var window = Window.GetWindow(this);
            window.KeyDown += HandleKeyPress;
        }

        private void HandleKeyPress(object sender, KeyEventArgs e)
        {
            //Do work
            switch (e.Key)
            {
                case Key.Escape:
                    this.Close();
                    break;
            }
        }


如果我有任何误解,您可以提供所有其他必要的代码段,以便其他人可以从头开始重现您的问题,以及有关结果的详细说明,包括任何异常消息.


If I have any misunderstanding, you can include all necessary code snippets for anyone else to be able to reproduce your issue from scratch along with a detailed description about the results including any exception messages.


如果您对Visual Studio有任何疑问,请访问 Visual Studio论坛以获得适当的帮助.


If you have any question about Visual Studio, please go to the Visual Studio forums for getting suitable help.


最好的问候,


Best Regards,

吕汉楠


这篇关于如何使退出键分配给退出按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆