如何在VB.NET 中限制文本框中只能输入数字
2个回答
展开全部
以下是只能输入数字和小数点,并且小数点只能输入一次
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textbox1.KeyPress
If Char.IsDigit(e.KeyChar) or e.KeyChar = Chr(8) or e.KeyChar = "." Then
If e.KeyChar = "." And InStr(TextBox1.Text, ".") > 0 Then
e.Handled = True
Else
e.Handled = False
End If
Else
e.Handled = True
End If
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textbox1.KeyPress
If Char.IsDigit(e.KeyChar) or e.KeyChar = Chr(8) or e.KeyChar = "." Then
If e.KeyChar = "." And InStr(TextBox1.Text, ".") > 0 Then
e.Handled = True
Else
e.Handled = False
End If
Else
e.Handled = True
End If
End Sub
展开全部
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
Select Case Asc(e.KeyChar)
Case 8, 45, 46 '退格,负号,小数点
Case 48 To 57 '0~9
Case Else
e.KeyChar = ""
End Select
End Sub
Select Case Asc(e.KeyChar)
Case 8, 45, 46 '退格,负号,小数点
Case 48 To 57 '0~9
Case Else
e.KeyChar = ""
End Select
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询