.NET文本框 - 处理Enter键 [英] .NET TextBox - Handling the Enter Key

查看:131
本文介绍了.NET文本框 - 处理Enter键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是明确根据用户的输入回车键( Keys.Enter )在.NET 执行动作的最佳途径文本框,假设导致燮回车键文本框本身的pression按键输入的所有权(e.Handled = TRUE)?

What is definitively the best way of performing an action based on the user's input of the Enter key (Keys.Enter) in a .NET TextBox, assuming ownership of the key input that leads to suppression of the Enter key to the TextBox itself (e.Handled = true)?

承担这个问题的目的是期望的行为是不脱preSS形式的默认按钮,而其他的一些自定义的处理应该发生的。

Assume for the purposes of this question that the desired behavior is not to depress the default button of the form, but rather some other custom processing that should occur.

推荐答案

添加一个关键preSS事件和告警输入键

Add a keypress event and trap the enter key

编程它看起来有点像这样:

Programmatically it looks kinda like this:

//add the handler to the textbox
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(CheckEnterKeyPress);

然后添加一个处理程序code ...

Then Add a handler in code...

private void CheckEnterKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
        if (e.KeyChar == (char)Keys.Return)

        {
           // Then Do your Thang
        }
}

这篇关于.NET文本框 - 处理Enter键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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