How do I prevent the caret going to the next line in a text box when the 'ENTER' key has been pressed? In other words how to disable the 'ENTER' or 'RETURN' key in a text-box?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can write the OnKeyDown
event. you can use the e.SuppressKeyPress
to tell .NET that you handle the key. Something like this:
if (e.KeyCode == Keys.Enter) {
e.SuppressKeyPress = true;
}
回答2:
Take a look at TextBox.AcceptsReturn
.