无法在文本框 keydown 事件上禁用哔声 [英] Cannot disable beep sound on textbox keydown event

查看:32
本文介绍了无法在文本框 keydown 事件上禁用哔声的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我在文本框KeyDown()事件上按Enter"时禁用哔声的代码:

Below is my code for disabling beep sound when I press "Enter" on textbox KeyDown() event:

if (e.KeyCode == Keys.Enter)
{
    e.SuppressKeyPress = true;
    SaveData();
    e.Handled = true;
}

但是当我在文本框上按Enter"键时它一直发出哔哔声.我做错了什么?

But it keeps beeping when I press "Enter" on textbox. What am I doing wrong?

推荐答案

EDIT

请注意,LarsTech 提供的答案(下文)是一种更好的方法.

Please note that the answer provided by LarsTech (below) is a far better approach.

抱歉,我刚刚发现您有一个 MessageBox 显示.

Sorry, I just realised that you have a MessageBox displaying.

你可以做的是有一个 Timer 并让它触发 SaveData() 方法.

What you can do is have a Timer and have it fire off the SaveData() method.

private void Timer1_Tick(System.Object sender, System.EventArgs e)
{
    Timer1.Enabled = false;
    SaveData();
}

然后在您的 TextBox 按键事件中,执行以下操作:

Then in your TextBox keypress event, do this:

if (e.KeyCode == Keys.Enter) {
    e.SuppressKeyPress = true;
    Timer1.Enabled = true;
}

这似乎有效...

这篇关于无法在文本框 keydown 事件上禁用哔声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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