在C#的winform的键盘快捷方式避免警报 [英] Avoiding alert on key board shortcut of C# winform
问题描述
我使用Visual Studio 2012年我的工作的快捷方式使完美的键盘快捷键,一个WinForm应用程序在C#。但是它给出了一个恼人的蜂鸣声
我添加 e.Handled = TRUE;
和 e.SuppressKeyPress = TRUE;根据多线程
。但它不工作,我的WinForm卡住。
我怎样才能避免这种情况?
私人无效textBoxSearch_KeyDown(对象寄件人,KeyEventArgs E)
{
如果(e.KeyCode == Keys.Down)
{
做的东西
}
,否则如果(如邀请码== Keys.Enter)
{
//做的东西
}
e.Handled = TRUE;
e.SuppressKeyPress = TRUE;
}
和我需要为这个太的解决方案。
保护覆盖布尔ProcessCmdKey(参考消息味精,钥匙KEYDATA)
{
如果(KEYDATA ==(Keys.Control |钥匙。 F))
{
//做的东西
}
,否则如果(KEYDATA ==(Keys.Control | Keys.G)){
//做的东西
}
返回base.ProcessCmdKey(REF味精,KEYDATA);
}
您有在KeyDown什么事件应该工作。该SupressKeyPress = TRUE停止对宝顶我,当我复制你的代码。
在给ProcessCmdKey事件中,你需要这样的:
保护覆盖布尔ProcessCmdKey(参考消息味精,钥匙KEYDATA)
{
如果(KEYDATA ==(Keys.Control | Keys.F))
{
//做的东西
返回;
}
,否则如果(KEYDATA ==(Keys.Control | Keys.G)){
//做的东西
的回报;
}
返回base.ProcessCmdKey(REF味精,KEYDATA);
}
I am making key board shortcuts to a Winform application in C# using Visual Studio 2012. My shortcuts work perfect. But it gives a annoying beep sound.
I added e.Handled = true;
and e.SuppressKeyPress = true;
according to many threads. But it does not work and my winform stuck.
How can I avoid this?
private void textBoxSearch_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Down)
{
do stuff
}
else if (e.KeyCode == Keys.Enter)
{
//do stuff
}
e.Handled = true;
e.SuppressKeyPress = true;
}
and I need a solution for this too.
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.F))
{
//do stuff
}
else if (keyData == (Keys.Control | Keys.G)) {
//do stuff
}
return base.ProcessCmdKey(ref msg, keyData);
}
What you have in the KeyDown event should work. The SupressKeyPress = true stopped the ding for me when I copied your code.
In the ProcessCmdKey event you would need this:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Control | Keys.F))
{
//do stuff
return;
}
else if (keyData == (Keys.Control | Keys.G)) {
//do stuff
return;
}
return base.ProcessCmdKey(ref msg, keyData);
}
这篇关于在C#的winform的键盘快捷方式避免警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!