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

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 TextBocx 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.