为什么按Ctrl +"+"在TextBox中发出提示音?

编程入门 行业动态 更新时间:2024-10-28 04:25:04
本文介绍了为什么按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:

  • 为什么此组合键会在TextBox中产生蜂鸣声.
  • 如何避免发出蜂鸣声?
  • 感谢您为此付出的一切努力. 更新: 我在美国/泰国键盘上尝试过它,并且也听到了提示音.无论我使用哪种逻辑键盘布局(德语,美国,泰语),都会发生这种情况. 在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中发出提示音?

    本文发布于:2023-07-11 08:54:16,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1093492.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:提示音   Ctrl   quot   TextBox

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!