Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当按下“ENTER”键时,如何防止插入符号转到文本框中的下一行?换句话说,如何禁用文本框中的“ENTER”或“RETURN”键?
您可以编写OnKeyDown事件。您可以使用e.SuppressKeyPress告诉 .NET 您处理密钥。像这样的东西:
OnKeyDown
e.SuppressKeyPress
if (e.KeyCode == Keys.Enter) { e.SuppressKeyPress = true; }
看看TextBox.AcceptsReturn。
TextBox.AcceptsReturn