9 个解决方案
#1
[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.csdn.net/mohongmao/archive/2008/11/30/3413951.aspx
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.csdn.net/mohongmao/archive/2008/11/30/3413951.aspx
#2
mark
#3
IsNumeric()
#4
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
If Not (Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57 Or Asc(e.KeyChar) = 8) Then
e.KeyChar = ""
End If
End Sub
#5
谢了哦!
#6
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
If e.KeyChar < "0" orelse e.KeyChar > "9" Then
e.handle=true
End If
End Sub
#7
正则表达式判断就行
#8
我就用这种
#9
http://topic.csdn.net/u/20081205/09/1503df66-b2cb-4a33-bd73-bd537c420c58.html
#1
[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.csdn.net/mohongmao/archive/2008/11/30/3413951.aspx
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.csdn.net/mohongmao/archive/2008/11/30/3413951.aspx
#2
mark
#3
IsNumeric()
#4
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
If Not (Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57 Or Asc(e.KeyChar) = 8) Then
e.KeyChar = ""
End If
End Sub
#5
谢了哦!
#6
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
If e.KeyChar < "0" orelse e.KeyChar > "9" Then
e.handle=true
End If
End Sub
#7
正则表达式判断就行
#8
我就用这种
#9
http://topic.csdn.net/u/20081205/09/1503df66-b2cb-4a33-bd73-bd537c420c58.html