如何制作仅接受数字的文本框?
问题: I have a windows forms app with a textbox control that I want to only accept integer values. 我有一个带有文本框控件的Windows窗体应用程序,我只想接受整数值。 In the past I've done this kind of validation by overloading the KeyPress event and just removing characters which didn't fit the specification. 过去,我通过重载KeyPress事件并仅删除不符合规范的字符来进行这种验证。 I've looked at the MaskedTextBox control but I'd like a more general solution that could work with perhaps a regular expression, or depend on the values of other controls. 我已经看过MaskedTextBox控件,但是我想要一个更通用的解决方案,它可以使用正则表达式,也可以依赖于其他控件的值。 Ideally this would behave such that pressing a