Have a textbox only allow whole numbers

I needed a textbox that will only allow numbers:

private void textBox_KeyPress(object sender, KeyPressEventArgs e) {

     if (e.KeyChar != 8 && char.IsNumber(e.KeyChar) == false) {

          e.Handled = true;

     }

}

Comments are closed.