Restrict Users To Input Only Numbers In Textbox Win Form C#

How to restrict users to input only numbers in TextBox control in windows form C#?


Please Subscribe Youtube| Like Facebook | Follow Twitter

In this tip we will write a code under KeyPress Event of TextBox control that will restrict user to type only numeric value in TextBox control in windows form C#.

private void TextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
     if (!Char.IsDigit(e.KeyChar))
          e.Handled = true;
}

Please Subscribe Youtube| Like Facebook | Follow Twitter


Leave a Reply

Your email address will not be published. Required fields are marked *