在TextBox中如何静音回车声音?

huangapple go评论72阅读模式
英文:

How to mute enter-perssed sound in TextBox?

问题

I have this simple code:

private void Term_TextBox_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyData == Keys.Enter)
        Definition_TextBox.Focus();
}

that focuses the next TextBox in my form after Enter was pressed. Unfortunately, there is this Windows-like "bung" or "bing" sound while pressing Enter in a TextBox. How to disable it?
I tried to google it but couldn't find any suitable answer. I don't want to mute the whole application, only this element, this exact TextBox. Do you know how to do it? Is there any 'elegant' solution to this problem? I'm using .NET Framework 4.7.2 with C#.
Thanks in advance.

英文:

I have this simple code:

private void Term_TextBox_KeyDown(object sender, KeyEventArgs e)
    if (e.KeyData == Keys.Enter)
        Definition_TextBox.Focus();

that focuses next TextBox in my form after enter was pressed. Unfortunetly there is this windows-like "bung"/"bing" sound while pressing entere in a TextBox. How to disable it?
I tried to google it but couldn't find any suitable answer. I don't want to mute whole application, only this element, this exact TextBox. Do you know how to do it? Is there any 'elegent' solution to this problem? I'm using .NET Framework 4.7.2 with c#.
Thanks in advance.

答案1

得分: 0

private void Term_TextBox_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyData == Keys.Enter)
    {
        e.SuppressKeyPress = True;
        Definition_TextBox.Focus();
    }
}

这是一个处理在 Windows Forms 中按下键盘按键事件的代码示例。当按下的按键是 Enter 键时,它会阻止默认的按键处理,并将焦点转移到 Definition_TextBox 控件上。

英文:
 private void Term_TextBox_KeyDown(object sender, KeyEventArgs e)
  if (e.KeyData == Keys.Enter)
    e.SuppressKeyPress = True
    Definition_TextBox.Focus();

https://learn.microsoft.com/de-de/dotnet/api/system.windows.forms.keyeventargs.suppresskeypress?view=windowsdesktop-7.0

huangapple
  • 本文由 发表于 2023年7月6日 19:02:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76628144.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定