在VB.NET中在文本框里输入字段看是否是数字,不用函数来判断
mohongmao»
[VB.NET]Text控制只可以填写数字
Private Sub TxtPrice_KeyPress(省略) Handles TxtPrice.KeyPress
'处理TEXT只可以输入数字和.键
Dim c As Char
c = e.KeyChar
If Not (Char.IsDigit(c) Or Char.IsControl(c) Or Asc(e.KeyChar) = 46) Then
'46表示按下的是.键
e.Handled = True
'e.handled表示取消keypress事件
End If
End Sub
我的博客http://blog.youkuaiyun.com/mohongmao/archive/2008/11/30/3413951.aspx
ayouaja»
mark
Hansfield»
IsNumeric()
kzccomputer»
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not (Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57 Or Asc(e.KeyChar) = 8) Then
e.KeyChar = ""
End If
End Sub
Cocokle»
谢了哦!
lizhengnan»
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar < "0" orelse e.KeyChar > "9" Then
e.handle=true
End If
End Sub
wuyq11»
正则表达式判断就行
mohongmao»
[VB.NET]Text控制只可以填写数字
Private Sub TxtPrice_KeyPress(省略) Handles TxtPrice.KeyPress
'处理TEXT只可以输入数字和.键
Dim c As Char
c = e.KeyChar
If Not (Char.IsDigit(c) Or Char.IsControl(c) Or Asc(e.KeyChar) = 46) Then
'46表示按下的是.键
e.Handled = True
'e.handled表示取消keypress事件
End If
End Sub
我的博客http://blog.youkuaiyun.com/mohongmao/archive/2008/11/30/3413951.aspx
ayouaja»
mark
Hansfield»
IsNumeric()
kzccomputer»
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not (Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57 Or Asc(e.KeyChar) = 8) Then
e.KeyChar = ""
End If
End Sub
Cocokle»
谢了哦!
lizhengnan»
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar < "0" orelse e.KeyChar > "9" Then
e.handle=true
End If
End Sub
wuyq11»
正则表达式判断就行