在窗口文本框中,我只想允许只有2个小数点。我可以只设置数字文本框,但不知道如何限制2个小数点。只允许2个小数点
例如,743.56
我的代码如下
Private Sub txtPrice_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPrice.KeyPress
'allow numeric
If Not Char.IsControl(e.KeyChar) AndAlso Not Char.IsDigit(e.KeyChar) AndAlso e.KeyChar <> "."c Then
e.Handled = True
End If
' only allow one decimal point
If e.KeyChar = "."c AndAlso TryCast(sender, TextBox).Text.IndexOf("."c) > -1 Then
e.Handled = True
End If
End Sub
如何?
按键响应不正确的事件。或者还不够。例如,它不会正确处理粘贴。 –
@Serge - appTranslator,用于粘贴,如何? – soclose