如何在WPF中执行此操作 [英] How to do this in WPF

查看:78
本文介绍了如何在WPF中执行此操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有很多窗户...我该怎么做...

我想在按ESC按钮时关闭表单..但我不想在所有窗口中都写上它.

我只想写在一个地方,并且每当用户调用ESC按钮时,活动窗口都应该关闭...

I have many windows in my project... How can i do this...

I want to close the form when i press the ESC button.. but i dont want to writw this in all the windows.

I just want to write in a single place and when ever a user calls a ESC button the active window should be close...

推荐答案

添加具有属性的按钮IsCancel = true.如果按ESCAPE键,则关闭窗体.
Add a button with the property IsCancel = true. If you press ESCAPE the form closes.


为Windows窗体创建子类.
捕获按键事件并如上所述检查ESC键或添加按钮.
从此新Form(而不是标准Windows Form)继承所有表单.

更改MyForm:表单



MyForm:SubclassedForm
Subclass a Windows Form.
Catch the keypress event and check for the ESC key or add a button as described above.
Inherit all your forms from this new Form instead of the standard Windows Form.

Change MyForm : Form

to

MyForm : SubclassedForm


这篇关于如何在WPF中执行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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