停止“鼎”时pressing进入 [英] Stop the 'Ding' when pressing Enter

查看:209
本文介绍了停止“鼎”时pressing进入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的Windows窗体应用程序。而且,在Windows(或,ATLEAST Windows窗体应用程序),当你美元,而单行TextBox控件里面,你听到丁p $ PSS输入。这是一个如意的声音,那表示你无法进入一个换行符,因为它是一个单行文本框。

这是所有罚款。然而,在我的表,我有1文本框和搜索按钮。而且我允许用户执行由pressing搜索,他们已经完成键入回车后,所以他们没有的有无的使用鼠标点击搜索按钮。

不过,出现这种声音鼎。这是非常恼人的。

我们怎样才能使它所以只是声音并不在我的表演呢?

@大卫^ h - 这里是我如何检测输入pressing:

 私人无效textBox1_KeyUp(对象发件人,发送KeyEventArgs E)
{
    如果(e.Key code == Keys.Enter)
    {
        //现在执行搜索。
    }
}


解决方案

查看<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.form.acceptbutton.aspx\">Form.AcceptButton属性。你可以用它来指定一个默认按钮的形式,在这种情况下为pressing进入。

从文档:


  

此属性允许您指定
  发生默认操作时,
  用户presses中回车键,
  应用。分配到按钮
  此属性必须是
  IButtonControl即在当前
  形成或位于容器内的上
  当前窗体。


还有一个<一href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.form.cancelbutton.aspx\">CancelButton属性当用户presses逃脱。

I have a very simple Windows Forms Application. And, in Windows (or, atleast Windows Forms Applications), when you press Enter while inside a Single-line TextBox Control, you hear a Ding. It's an unpleasent sound, that indicated you cannot enter a newline, because it is a single-line TextBox.

This is all fine. However, in my Form, I have 1 TextBox, and a Search Button. And I am allowing the user to Perform a search by pressing Enter after they've finished typing, so they don't have to use the mouse to click the Search Button.

But this Ding sound occurs. It's very annoying.

How can we make it so just that sound doesn't play at all in my Form?

@David H - Here's how I'm detecting the enter pressing:

private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        // Perform search now.
    }
}

解决方案

Check out the Form.AcceptButton property. You can use it to specify a default button for on a form, in this case for pressing enter.

From the docs:

This property enables you to designate a default action to occur when the user presses the ENTER key in your application. The button assigned to this property must be an IButtonControl that is on the current form or located within a container on the current form.

There is also a CancelButton property for when the user presses escape.

这篇关于停止“鼎”时pressing进入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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