Thursday, September 29, 2011

textbox should accept numbers only

1. write the code below in your textbox keypress event


private void txtPincode_KeyPress(object sender, KeyPressEventArgs e)
  {
      if ((e.KeyChar >= 48 && e.KeyChar <= 57) || (e.KeyChar == 8))//keychar 8 is for backspace
            {
                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
  }

No comments:

Post a Comment