C#如何禁用一个键 [英] C# How do disable a key
本文介绍了C#如何禁用一个键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当按下ENTER键时,如何防止插入符号进入文本框中的下一行?换句话说,如何在文本框中禁用ENTER或RETURN键?
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?
推荐答案
OnKeyDown
事件。您可以使用 e.SuppressKeyPress
来告诉.NET处理密钥。如下所示:
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;
}
这篇关于C#如何禁用一个键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文