如何在 C# 中跳过文本框的输入?
我想从 C# 的 TextBox 组件扩展一个类并重写“On[Event]”方法,以便检查在文本框中键入的输入并跳过要在文本框中输入的一些键。我正在寻找这样的东西(以下代码不是解决方案!):
public class NumText : TextBox
{
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyValue >= 48 && e.KeyValue <= 57)
base.OnKeyDown(e);
}
}
I want to extend a class from TextBox component of C# and override an "On[Event]" method in order to check the input of typing in text box and skip some keys to be entered in the text box. I'm search for something like this (the following code is not the solution!):
public class NumText : TextBox
{
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyValue >= 48 && e.KeyValue <= 57)
base.OnKeyDown(e);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,只是不要覆盖事件,如果您需要防止按下多个键,请添加一个新事件。
Well just don't override the Event ,add a new Event instead if you need to prevent several Key's being pressed .
使用 KeyEventArgs.Handled 属性。
引用MSDN文章:
Use KeyEventArgs.Handled Property.
Quote to MSDN article :