标签:
Private Sub textbox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textbox1.KeyPress
If e.KeyChar = Chr(8) Then Exit Sub
If InStr(textbox1.Text, ".") = 0 Then textbox1.MaxLength = 12 Else textbox1.MaxLength = 13
If Len(textbox1.Text) - InStr(textbox1.Text, ".") = 5 And Len(textbox1.Text) <> 5 Then e.KeyChar = Chr(0)
If Len(textbox1.Text) = 7 And InStr(textbox1.Text, ".") = 0 Then
e.KeyChar = "."
Else
e.Handled = False
End If
If e.KeyChar = Chr(46) And InStr(textbox1.Text, ".") = 0 Then Exit Sub
If e.KeyChar < Chr(48) Or e.KeyChar > Chr(57) Then e.KeyChar = Chr(0)
End Sub
实现textbox只能输入X.Y的小数,最大7位,Y最大5位。
vb.net实现textbox控件输入指定位数小数方法实现。
标签:
原文地址:http://www.cnblogs.com/sd5116620/p/5588847.html