为什么按Ctrl +"+"在TextBox中发出提示音? [英] Why does pressing Ctrl+"+" produce a beep in a TextBox?

查看:118
本文介绍了为什么按Ctrl +"+"在TextBox中发出提示音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#Windows Forms,并且想将Ctrl+"Oemplus"用作我的应用程序的功能key.我使用German keyboard,此键位于字母P右边的2个键(即"+").每当我同时按下此键和Ctrl并将焦点放在TextBox上时,都会发出蜂鸣声.
当我切换到US keyboard布局(仍然使用我的German keyboard)时,也会发生这种情况.这就是] key.
Internet Explorers地址栏中按此键时,也会发生同样的情况. 我的问题是:

I am Working with C# and Windows Forms and want to use Ctrl+"Oemplus" as a function key for my application. I use a German keyboard and this key is located 2 keys right of the letter P (that ist then "+"). Whenever I press this key in combination with Ctrl and the focus is on a TextBox I get a beep.
This also happens when I switch to an US keyboard layout (still using my German keyboard). This is then the ] key.
The same happens when pressing this key while in Internet Explorers address bar. My question is:

  1. 为什么此组合键会在TextBox中产生蜂鸣声.
  2. 如何避免发出蜂鸣声?

感谢您为此付出的一切努力.
更新:
我在美国/泰国键盘上尝试过它,并且也听到了提示音.无论我使用哪种逻辑键盘布局(德语,美国,泰语),都会发生这种情况.
在Windows资源管理器中,地址栏也会发出蜂鸣声,但搜索框中不会发出蜂鸣声.

Thanks for any efforts you put on this.
Update:
I tried it on an US/Thai keyboard and get the beep as well. This happens no matter what logical keyboard layout I use (German, US, Thai).
The beep also happens in Windows Explorer in the address bar but not in the search box.

推荐答案

我相信正在发生的事情是Textbox不允许使用组合键,因此会出现错误.您可以通过此代码(在EN Windows中使用右括号键)测试它的键组合,它使用的是

What I believe is happening is that the key combination is not allowed for the Textbox, therefore you are getting the error. You can test for the Key Combination by this code( using the right bracket key in EN Windows) it is using SuppressKeyPress to prevent the Key Combination from being passed to the underlying control to prevent the beep.

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (ModifierKeys == Keys.Control)
        if (e.KeyValue == 221) // You may need to determine this value for your keyboard layout.
        {
            textBox1.Text += " + "; // Handle the Key combination.
            e.SuppressKeyPress = true;  // Prevents key from being passed to underlying control
        }

}

这篇关于为什么按Ctrl +"+"在TextBox中发出提示音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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