Saturday, August 31, 2013

How do make the texbox accept only numerics, del key and backspace?

hi friends,


is there away to make a textbox accept only numeric, del key and backspace key?


I used the following code but it doesn't work:



private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if ( char.IsDigit(e.KeyChar) == true || e.KeyChar == Convert.ToChar(Keys.Back) || e.KeyChar == Convert.ToChar(Keys.Delete) )
{
e.Handled = true;
}
}



thanks


I use Visual studio 2010 professional and SQL server 2008 developer edition!


No comments:

Post a Comment