本文介绍了禁用ALT + F4但允许的形式,由code被关闭,CloseReason.UserClosing是没有帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想,窗体不会关闭通过执行替代骨节病> + F4 骨节病>但是,如果 Application.Exit()
或 this.Close
从相同的形式被调用时,应当将其关闭。
I want that the form will not close by doing + but if Application.Exit()
or this.Close
is called from the same Form, it should be closed.
我试过 CloseReason.UserClosing
,但仍然无济于事。
I tried CloseReason.UserClosing
but still no help.
推荐答案
如果您需要过滤掉替代骨节病> + F4关闭箱骨节病>事件只(留点击, this.Close()
和 Application.Exit()
来表现像往常一样),那么我可以建议如下:
If you need to filter out + event only (leaving clicking of close box, this.Close()
and Application.Exit()
to behave as usual) then I can suggest the following:
- 设置窗体的
键preVIEW
属性真
; -
电线表单的
的FormClosing
和的事件:
- Set form's
KeyPreview
property totrue
; Wire up form's
FormClosing
andKeyDown
events:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (_altF4Pressed)
{
if (e.CloseReason == CloseReason.UserClosing)
e.Cancel = true;
_altF4Pressed = false;
}
}
private bool _altF4Pressed;
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Alt && e.KeyCode == Keys.F4)
_altF4Pressed = true;
}
这篇关于禁用ALT + F4但允许的形式,由code被关闭,CloseReason.UserClosing是没有帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!