Monday, December 13, 2010

Keypress- only press keys from 1 to 9

Private Sub txtNumber_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNumber.KeyPress

If (e.KeyChar < "1" Or e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If

End Sub

1 comment:

  1. Do this to include the decimal point:
    If (e.KeyChar < "1" Or e.KeyChar > "9") AndAlso e.KeyChar <> ControlChars.Back AndAlso e.KeyChar <> "." Then e.Handled = True

    ReplyDelete