在窗口文本框中,我只想允許只有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