Only accept digits for textbox

前端 未结 8 969
小鲜肉
小鲜肉 2020-12-10 16:13

I found this code for making my textbox only accept numbers.

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.Key         


        
8条回答
  •  青春惊慌失措
    2020-12-10 16:41

    You also need to handle pasted text (there may not be a keypress). The best way to do this is with a MaskedTextBox.

提交回复
热议问题