how to make this line read the delete key back

1

I am using this line so that in a TextBox it is only numbers what it reads but when I make it delete with the back key it reads as if it were a letter; How do I solve it?

 Private Sub txt_id_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txt_id.KeyPress
        If Not Char.IsNumber(e.KeyChar) Then
            e.Handled = False
            MessageBox.Show("Introduzca sólo valores númericos")
        End If
    
asked by fabro 30.11.2017 в 16:41
source

1 answer

1

Good Fabro,

You can use the following:

 Private Sub txt_id_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txt_id.KeyPress
        If Not Char.IsNumber(e.KeyChar) And e.KeyChar <> ControlChars.Back Then
            e.Handled = False
            MessageBox.Show("Introduzca sólo valores númericos")
        End If
    
answered by 30.11.2017 в 16:48