gpt4 book ai didi

.NET TextBox - 处理 Enter 键

转载 作者:行者123 更新时间:2023-12-03 08:15:56 24 4
gpt4 key购买 nike

根据用户在 .NET 中输入的 Enter 键 ( Keys.Enter ) 来执行操作的最佳方式是什么 TextBox ,假设键输入的所有权导致抑制文本框本身的 Enter 键(e.Handled = true)?

出于此问题的目的,假设所需的行为不是按下表单的默认按钮,而是应该发生的一些其他自定义处理。

最佳答案

添加按键事件并捕获回车键

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

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

然后在代码中添加一个处理程序...
private void CheckEnterKeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)

{
// Then Do your Thang
}
}

关于.NET TextBox - 处理 Enter 键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3558814/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com