我正在使用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:
感谢您为此付出的一切努力. 更新: 我在美国/泰国键盘上尝试过它,并且也听到了提示音.无论我使用哪种逻辑键盘布局(德语,美国,泰语),都会发生这种情况. 在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中使用右括号键)测试它的键组合,它使用的是 SuppressKeyPress ,以防止将键组合传递给基础控件以防止发出蜂鸣声.
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中发出提示音?
发布评论