.NET TextBox - Handling the Enter Key(.NET TextBox - 处理 Enter 键)
问题描述
在 .NET TextBox 中,根据用户输入的 Enter 键 (Keys.Enter),假设拥有导致 TextBox 本身的 Enter 键被抑制的键输入(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)?
出于此问题的目的,假设所需的行为不是按下表单的默认按钮,而是应该发生的其他一些自定义处理.
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.
推荐答案
添加按键事件并捕获回车键
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);
然后在代码中添加处理程序...
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 TextBox - 处理 Enter 键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.NET TextBox - 处理 Enter 键
基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
