How to validate text boxes, which only supports numbers

0

I have 3 text boxes where I should only enter numbers and if a letter is written simply do not show it, as if I had not typed it. For Windows forms

private void TBCausacion_KeyPress(object sender, KeyPressEventArgs e)
    {

    }
    
asked by Saul Salazar 15.08.2018 в 00:32
source

1 answer

1

Try adding this to your friend method.

private void TBCausacion_KeyPress(object sender, KeyPressEventArgs e)
{
   e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
}

I hope I help you.

Greetings.

    
answered by 15.08.2018 / 00:39
source