根据用户在.NET TextBox中输入的Enter键(Keys.Enter)执行操作的最佳方式是什么(假设拥有导致取消TextBox本身Enter键的键输入的所有权) (e.Handled = true)?
出于这个问题的目的,假设所需的行为不是按下窗体的默认按钮,而是应该发生的一些其他自定义处理。
发布于 2010-08-25 00:49:33
添加一个按键事件并捕获enter键
从编程上看,它看起来有点像这样:
//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
}
}https://stackoverflow.com/questions/3558814
复制相似问题