How do I make a textbox that only accepts numbers?

后端 未结 30 1580
梦如初夏
梦如初夏 2020-11-21 06:05

I have a windows forms app with a textbox control that I want to only accept integer values. In the past I\'ve done this kind of validation by overloading the KeyPress event

30条回答
  •  死守一世寂寞
    2020-11-21 06:51

    Take a look at Input handling in WinForm

    I have posted my solution which uses the ProcessCmdKey and OnKeyPress events on the textbox. The comments show you how to use a Regex to verify the keypress and block/allow appropriately.

提交回复
热议问题