You need to use the keydown and keypress methods for each box that you are limiting. You also have to allow the - and . keys as well as all of the numpad ones.
Keydown calls this
This goes within keyPress:Code: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
Hope that helpsCode:' Check for the flag being set in the KeyDown event. If nonNumberEntered = True Then ' Stop the character from being entered into the control since it is non-numerical. e.Handled = True End If
Jim




Reply With Quote