Private Sub OnlyNumbers(ByVal e As System.Windows.Forms.KeyEventArgs)
' Initialize the flag to false.
nonNumberEntered = False
' Determine whether the keystroke is a number from the top of the keyboard.
If e.KeyCode < Keys.D0 OrElse e.KeyCode > Keys.D9 Then
' Determine whether the keystroke is a number from the keypad.
If e.KeyCode < Keys.NumPad0 OrElse e.KeyCode > Keys.NumPad9 Then
' Determine whether the keystroke is a backspace.
If e.KeyCode <> Keys.Back Then
' Determine whether the keystroke is a . or a - on either the main keyboard or keypad
If e.KeyCode <> Keys.Subtract Then 'keypad
If e.KeyCode <> Keys.Decimal Then 'keypad
If e.KeyCode <> Keys.OemPeriod Then 'keyboard
If e.KeyCode <> Keys.OemMinus Then 'keyboard
' A non-numerical keystroke was pressed.
' Set the flag to true and evaluate in KeyPress event.
nonNumberEntered = True
End If
End If
End If
End If
End If
End If
End If
End Sub