题
如何在按下返回键后取消文本框中的按键事件。
解决方案
将KeyPressEventArgs处理程序参数的Handled属性设置为true。
来自msdn的例子:
private void keypressed(Object o, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Return)
{
e.Handled = true;
}
}
请参阅 http:// msdn。 microsoft.com/en-us/library/system.windows.forms.keypresseventargs.handled.aspx 了解更多信息。
其他提示
您的意思是,您希望它忽略回车键吗?
你可以添加一个keydown事件并忽略那里的回车键......
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.SuppressKeyPress = true;
}
}
不隶属于 StackOverflow