开发者

How do I prevent the textedit box from beeping when enter is pressed?

开发者 https://www.devze.com 2023-02-10 13:07 出处:网络
I have a text edit field in a Windows Form C# application I am developing and after the function occurs, windows dings.I found some solutions but it applied only to C++ and I couldn\'t figure how to t

I have a text edit field in a Windows Form C# application I am developing and after the function occurs, windows dings. I found some solutions but it applied only to C++ and I couldn't figure how to translate it making the key event to zero since it is a char and illegal cast, even if i do manually cast it to char, it still beeps.

Any help is greatly appreciated!

private void txtPhrase_KeyPress(object sender, KeyPressEventArgs e)
{
            if (e.KeyChar == (char)13)
            {开发者_如何转开发
                // keyPress seems to initiate the system beep.  Why?
                btnSpeak_Click(sender, e);

            }

 }


You have to prevent the keystroke from reaching the native control. Set e.Handled = true

0

精彩评论

暂无评论...
验证码 换一张
取 消