如何防止由于一个WinForms TextBox中按下Alt键的蜂鸣声? [英] How to prevent the beep sound caused by alt key pressed in a WinForms TextBox?

查看:306
本文介绍了如何防止由于一个WinForms TextBox中按下Alt键的蜂鸣声?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个程序,它允许用户复制的键盘快捷方式转化为自定义快捷键定制一个文本框,但每alt键被按下另一个字母时,会产生另一种声音。

I'm creating a routine that allows the user to replicate keyboard shortcuts into a textbox for 'custom keyboard shortcuts' customization, but every time the alt key is pressed with another letter, it produces another sound.

我捕捉键在textbox_keydown事件修饰符+其他键解析为可读Shift + A键或Ctrl + Shift + B键的方式成同样的文本框。我应该像textbox_previewkey而不是textbox_keydown不同的事件做这个?我怎样才能防止ALT修饰键+一个字母或数字引起蜂鸣声?

I'm capturing the keys in the textbox_keydown event to parse the modifiers + other keys into a readable Shift + A or Ctrl + Shift + B manner into that very same textbox. Should I be doing this in a different event like textbox_previewkey instead of textbox_keydown? How can I prevent the alt modifier key + a letter or number causing the Beep sound?

文本框仅仅是一个普通的.NET 3.5文本框与它的唯一的编辑的属性作为只读属性设置为false。有没有更好的办法,我可以重新做到这一点?

the textbox is just a normal .net 3.5 textbox with the only edited properties of it being the ReadOnly property to false. Is there a better way I could re-do this?

我目前只是检查,如果按下任何修饰键,然后+ AZ或0-9,然后继续前进,并输入相应按键成同文本框像Shift + A键或按Ctrl + Shift + Y

I'm currently just checking that if any modifiers keys are pressed and then + a-z or 0-9, then to go ahead and input the appropriately pressed keys into that same textbox like Shift + A or Ctrl + Shift + Y.

推荐答案

处理文本框,如的KeyDown事件与无效HandleKeyDown(对象源,KeyEventArgs e)和内输入:如果(e.Alt)e.SuppressKeyPress = TRUE;

Handle the KeyDown event of the TextBox, e.g. with void HandleKeyDown(object source, KeyEventArgs e) and inside enter: if (e.Alt) e.SuppressKeyPress = true;.

(也适用于回车键)

干杯,
tamberg

Cheers, tamberg

这篇关于如何防止由于一个WinForms TextBox中按下Alt键的蜂鸣声?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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