Private Sub textbox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textbox1.KeyPress If e.KeyChar ...
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位。