本文介绍了限制按键事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我已使用按键按下事件来修复某些事件的快捷方式.
其实我有F4的固定代码.但是当我按Ctrl + F4的时候,Shift + F4的时间
也可以执行F4代码.
如何限制呢?
谢谢&Regards,
Pal
Hi All,
I have used key down event to fix shortcut for some events.
Actually I have Fixed code for F4. But when I press Ctrl+F4,Shift +F4 that time
also that F4 code gets executed.
How to restrict this?
Thanks &Regards ,
Pal
推荐答案
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F4 || (e.KeyCode == Keys.F4 && Control.ModifierKeys == Keys.Control) || (e.KeyCode == Keys.F4 && Control.ModifierKeys == Keys.Alt) || (e.KeyCode == Keys.F4 && Control.ModifierKeys == Keys.Control && Control.ModifierKeys == Keys.Alt))
{
//doNothing();
}
else
{
//DoStuff();
}
}
上面的示例在与修饰符的每种组合中都限制了F4键.
快乐编码:)
The example above restricts F4 key in every combination with modifiers.
Happy Coding :)
这篇关于限制按键事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!